Gradle systax error given code to generate random value

I get a syntax error of

Invalid variable name. Must start with a letter but was: ​dbPortBase

when I have this at the beginning of my gradle.build file

Integer dbPortBase = 5000;
Integer DB_PORT = Math.abs(new Random().nextInt(999));
DB_PORT +=​dbPortBase​;

I'm trying to set up for ci such that I can pass a random port in for db port for use in Multibranch ci env. Seems to be valid java/groovy code. I don't know what is not valid about it.

I tried changing def to Integer, uppercase variable name, lowercase name, separation of addition a = a + b instead of a+=b no luck. any advice?

1 answer

  • answered 2018-02-13 02:40 claya

    it accepted this

    Integer db_PortBase = 5000;
    Integer dbPort = Math.abs(new Random().nextInt(999));
    dbPort = dbPort + db_PortBase​;