diff --git a/src/main/groovy/com/palantir/gradle/javadist/JavaDistributionPlugin.groovy b/src/main/groovy/com/palantir/gradle/javadist/JavaDistributionPlugin.groovy index bce245b1..a5c41d87 100644 --- a/src/main/groovy/com/palantir/gradle/javadist/JavaDistributionPlugin.groovy +++ b/src/main/groovy/com/palantir/gradle/javadist/JavaDistributionPlugin.groovy @@ -19,6 +19,7 @@ import com.palantir.gradle.javadist.tasks.* import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.plugins.JavaPlugin class JavaDistributionPlugin implements Plugin { @@ -53,7 +54,8 @@ class JavaDistributionPlugin implements Plugin { LaunchConfigTask launchConfig = project.tasks.create('createLaunchConfig', LaunchConfigTask) project.afterEvaluate { launchConfig.configure(distributionExtension.mainClass, distributionExtension.args, distributionExtension.checkArgs, - distributionExtension.defaultJvmOpts, distributionExtension.javaHome, distributionExtension.env) + distributionExtension.defaultJvmOpts, distributionExtension.javaHome, distributionExtension.env, + project.tasks[JavaPlugin.JAR_TASK_NAME].outputs.files + project.configurations.runtime) } Task initScript = project.tasks.create('createInitScript', CreateInitScriptTask) diff --git a/src/main/groovy/com/palantir/gradle/javadist/tasks/LaunchConfigTask.groovy b/src/main/groovy/com/palantir/gradle/javadist/tasks/LaunchConfigTask.groovy index 9709649a..93a8bce6 100644 --- a/src/main/groovy/com/palantir/gradle/javadist/tasks/LaunchConfigTask.groovy +++ b/src/main/groovy/com/palantir/gradle/javadist/tasks/LaunchConfigTask.groovy @@ -23,10 +23,10 @@ import groovy.transform.EqualsAndHashCode import groovy.transform.ToString import org.gradle.api.DefaultTask import org.gradle.api.file.FileCollection -import org.gradle.api.plugins.JavaPlugin import org.gradle.api.tasks.Input -import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction import java.nio.file.Files @@ -46,11 +46,15 @@ class LaunchConfigTask extends DefaultTask { List defaultJvmOpts @Input - Map env + Map env + @Input @Optional String javaHome + @InputFiles + FileCollection classpath + LaunchConfigTask() { group = JavaDistributionPlugin.GROUP_NAME description = "Generates launcher-static.yml and launcher-check.yml configurations." @@ -67,7 +71,7 @@ class LaunchConfigTask extends DefaultTask { List classpath List jvmOpts List args - Map env + Map env } @OutputFile @@ -100,8 +104,7 @@ class LaunchConfigTask extends DefaultTask { config.mainClass = mainClass config.javaHome = javaHome ?: "" config.args = args - config.classpath = relativizeToServiceLibDirectory( - project.tasks[JavaPlugin.JAR_TASK_NAME].outputs.files + project.configurations.runtime) + config.classpath = relativizeToServiceLibDirectory(classpath) config.jvmOpts = defaultJvmOpts config.env = env return config @@ -113,12 +116,13 @@ class LaunchConfigTask extends DefaultTask { return output } - public void configure(String mainClass, List args, List checkArgs, List defaultJvmOpts, String javaHome, Map env) { + public void configure(String mainClass, List args, List checkArgs, List defaultJvmOpts, String javaHome, Map env, FileCollection classpath) { this.mainClass = mainClass this.args = args this.checkArgs = checkArgs this.defaultJvmOpts = defaultJvmOpts this.javaHome = javaHome this.env = env + this.classpath = classpath } } diff --git a/src/test/groovy/com/palantir/gradle/javadist/JavaDistributionPluginTests.groovy b/src/test/groovy/com/palantir/gradle/javadist/JavaDistributionPluginTests.groovy index 02a26b48..e92a67ee 100644 --- a/src/test/groovy/com/palantir/gradle/javadist/JavaDistributionPluginTests.groovy +++ b/src/test/groovy/com/palantir/gradle/javadist/JavaDistributionPluginTests.groovy @@ -72,6 +72,46 @@ class JavaDistributionPluginTests extends GradleTestSpec { exec('dist/service-name-0.1/service/monitoring/bin/check.sh') ==~ /(?m)Checking health of 'service-name'\.\.\.\s+Healthy.*\n/ } + def 'packaging tasks re-run after version change'() { + given: + createUntarBuildFile(buildFile) + buildFile << ''' + distribution { + enableManifestClasspath true + } + task untar02 (type: Copy) { + from tarTree(resources.gzip("${buildDir}/distributions/service-name-0.2.sls.tgz")) + into "${projectDir}/dist" + dependsOn distTar + } + '''.stripIndent() + file('src/main/java/test/Test.java') << ''' + package test; + public class Test { + public static void main(String[] args) { + while(true); + } + } + '''.stripIndent() + + when: + runSuccessfully(':build', ':distTar', ':untar') + buildFile << ''' + version '0.2' + '''.stripIndent() + + then: + def version02BuildOutput = runSuccessfully(':build', ':distTar', ':untar02').output + version02BuildOutput ==~ /(?m)(?s).*^:createCheckScript UP-TO-DATE$.*/ + version02BuildOutput ==~ /(?m)(?s).*^:createInitScript UP-TO-DATE$.*/ + version02BuildOutput ==~ /(?m)(?s).*^:createLaunchConfig$.*/ + version02BuildOutput ==~ /(?m)(?s).*^:createManifest$.*/ + version02BuildOutput ==~ /(?m)(?s).*^:manifestClasspathJar$.*/ + version02BuildOutput ==~ /(?m)(?s).*^:distTar$.*/ + exec('dist/service-name-0.2/service/bin/init.sh', 'start') ==~ /(?m)Running 'service-name'\.\.\.\s+Started \(\d+\)\n/ + exec('dist/service-name-0.2/service/bin/init.sh', 'stop') ==~ /(?m)Stopping 'service-name'\.\.\.\s+Stopped \(\d+\)\n/ + } + def 'status reports when process name and id don"t match'() { given: createUntarBuildFile(buildFile)