Application plugin: export CLASSPATH instead of using command line argument

I’m using gradle for several Java projects, in which I’m also using the gradle start scripts generated by distZip or starting the program with ‘gradle run’. While this eases the handling of the classpath, the management afterwards is awkward because of the extremely long -classpath argument on the java command line due to all the jars of the dependences being on the command line. This results in a long output from something such as ‘ps aux’ or something similar and also makes it hard to find out which program is actually running.

The start script contains a line similar to

java … -classpath “$CLASSPATH” my.main.class “$@”

A much cleaner process name result from using

export $CLASSPATH java … my.main.class “$@”

The CLASSPATH variable is already built in the start script, so why not just export it rather than passing it as a command line argument? Since it’s exported in the shell script in the newly spawned shell, it will not clutter the outer CLASSPATH variable after the program terminates.

The same thing would be preferabble in programs started using ‘gradle run’.

Hi Egbert,

There are some changes coming in Gradle 2.4 that will allow you to customize the scripts generated by application plugin. This should allow you to implement this.

We won’t be able to change the scripts to use this strategy by default as some existing users rely on the current behaviour.

I was able to create a custom JavaExec task in my build.gradle that uses the environmental variable CLASSPATH, so that is quite permanent. Modifying the generated scripts would be a great feature, currently I have to make the (small) change manually after every build.

Thanks for the reply!