Issue
I have a working Maven build (shown below) that prepares a couple of executables to launch as two separate processes.
Although this works fine, how can this be done using Gradle? I see that Gradle provides a plugin called application
, but I have a hard time finding a nice example on how to tell it that when typing: gradle stage
, it should create 2 executables.
Right now when I call stage
it only provides an executable on the "root" mainclass defined in my gradle script:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'SpringLauncher'
applicationName = 'foo'
compileJava.options.encoding = 'UTF-8'
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
task stage(dependsOn: ['clean', 'installApp', 'hello'])
And the Maven build:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<assembleDirectory>target</assembleDirectory>
<programs>
<program>
<mainClass>foo.bar.scheduler.SchedulerMain</mainClass>
<name>scheduler</name>
</program>
<program>
<mainClass>SpringLauncher</mainClass>
<name>web</name>
</program>
</programs>
</configuration>
<executions>
<execution>
<phase>package</phase><goals><goal>assemble</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
Solution
Unfortunately the gradle application plugin does not provide first class support for multiple executable scripts.
Luckily though, because gradle scripts are groovy, you can change what the application plugin does reasonably easily.
The documentation for the Application plugin show that the startScripts
task is of type CreateStartScripts, so try creating yourself a second task of the same type
task schedulerScripts(type: CreateStartScripts) {
mainClassName = "foo.bar.scheduler.SchedulerMain"
applicationName = "scheduler"
outputDir = new File(project.buildDir, 'scripts')
classpath = jar.outputs.files + project.configurations.runtime
}
then include the output of that task in your distribution
applicationDistribution.into("bin") {
from(schedulerScripts)
fileMode = 0755
}
Answered By - Perryn Fowler
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)