Use multiple tomcat ports

Hello,
our company doing a project in cuba platform in this project we are 4 developer and we use different Ports and database.

our problem is when we do push commit build.gradle on Git. The ports number will be who is commit then other developer pull commit then they want to change ports again in project properties so that we are planing to create a configurations file or create external variable in build.gradle.

Here

    tomcat {
        dir = "$project.rootDir/build/tomcat"
        port = 11431
        shutdownPort = 11433
        ajpPort = 11432
        debugPort = 11434
    }

I would like to use Variable instead of this numbers. is that possible?
and I try to create a variable in gradle,properties
tomcat_port=11431

and in the build.gradle

 tomcat {
        dir = "$project.rootDir/build/tomcat"
        port = "${tomcat_ports}"
        shutdownPort = 11433
        ajpPort = 11432
        debugPort = 11434
    }

but it was not work.

if there any possible was use external variable in build.gradle.
please help me.

thank you

Hi,
Not sure if you have resolved this problem. but here is the solution:
in gradle.properties under your home directory’s .gradle dir, add this:

projectOneTomcatPort=11431
projectTwoTomcatPort=11531

then you can use this in your build.gradle:

 tomcat {
        dir = "$project.rootDir/build/tomcat"
        port = projectOneTomcatPort
...
    }

thank you for your replay

the problem is not solved.
when i use above code that you send it is not working .
when i use this code Cuba studio not recognizance this variable and it change ports into default value (8080).

can we use value in Yaml file pass to build.gradle in cuba project?
Is that possiable?

Hi,
that’s because CUBA still have some hard coded port numbers in *.properties files. You can make a full search in your IDE, see what are those files.
The solution is:
In *.properties files, use @ token to mark gradle properties, e.g:

cuba.webAppUrl = http://localhost:@projectOneTomcatPort@/app

then, in your build.gradle file, add processResources to replace gradle properties at build time. Recommend to add the process in globalModule configure as below. Don’t forget to import ReplaceTokens .

import org.apache.tools.ant.filters.ReplaceTokens
configure(globalModule) {
    entitiesEnhancing {
        main {
            enabled = true
        }
    }
    processResources {
        filter(ReplaceTokens, tokens: [projectOneTomcatPort: projectOneTomcatPort])
    }
}

Finally you can rebuild your project, see how this could work.

Hi,

The current Studio 6.x is unable to parse arbitrary language constructs, so it works only with hardcoded numbers in port values.
The upcoming Studio 7 based on IntelliJ Platform will support much more flexibility in writing build scripts, including the ports defined elsewhere.

Regards,
Konstantin

1 Like