diff --git a/README.md b/README.md index da68e93187ecd82f5240db9fd5ade045a23584f4..74fb05aa17981d02d4fe23b5ecabd9b0568e35df 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,12 @@ cpublish { If a commit lands on master, and `cpublish.skip` is false, you can have confidence that the gradle `project.version` includes a new value. Running `gradle uploadArchives` to publish a new release will work. -TODO: currently depend on Jenkins to tag the release, provide a task to do this from Gradle +After the `uploadArchives` task completes, you can have Jenkins tag the release and push the tag to the repository. + +1. In your Jenkins build job, in the **Build** section, add a `Execute system Groovy script` step, and have it run a copy of the provided [artifact-version.groovy](artifact-version.groovy). +2. In the same job, in the **Post-build actions** section, add a `Git Publisher` step, and configure it: + + ## Developing the plugin diff --git a/artifact-version.groovy b/artifact-version.groovy new file mode 100644 index 0000000000000000000000000000000000000000..aaf7e09414c1613460c26e0c3e71c04c4ec59c26 --- /dev/null +++ b/artifact-version.groovy @@ -0,0 +1,17 @@ +// Script executed by Jenkins build +// Get project version version and assign to ARTIFACT_VERSION parameter +import hudson.model.* +import java.util.jar.* +def build = Thread.currentThread().executable + +Manifest manifest = new Manifest( + new FileInputStream( + new File("${build.workspace}/build/tmp/jar/MANIFEST.MF"))); + +def version = manifest.getAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION) +println "Artifact version is $version" +build.addAction( + new ParametersAction([ + new StringParameterValue("ARTIFACT_VERSION", version), + ]) +) diff --git a/build.gradle b/build.gradle index 0314851b4dc47ccd3036d2db0156af0925fe8779..4e99f2515867b1b3c2b7b16063ffbcc739e2e53e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'edu.wisc.doit.gradle' -version '0.1.1' +version '0.2.0' apply plugin: 'groovy' apply plugin: 'idea' @@ -26,7 +26,14 @@ publishing { } } } - +jar { + manifest { + attributes( + 'Implementation-Title': project.name, + 'Implementation-Version': project.version, + ) + } +} uploadArchives { repositories { mavenDeployer { diff --git a/git-publisher-config.png b/git-publisher-config.png new file mode 100644 index 0000000000000000000000000000000000000000..939c7ff9f36deb90c7c09b7b73b8cd6e68f8580e Binary files /dev/null and b/git-publisher-config.png differ diff --git a/src/main/groovy/edu/wisc/doit/gradle/ContinuousPublishPlugin.groovy b/src/main/groovy/edu/wisc/doit/gradle/ContinuousPublishPlugin.groovy index 8c9e535e0be34ef3aaf61c8014be1ad72da62b3b..df1a1be2bf33d1016ddad5e63e31ce568efcf5cd 100644 --- a/src/main/groovy/edu/wisc/doit/gradle/ContinuousPublishPlugin.groovy +++ b/src/main/groovy/edu/wisc/doit/gradle/ContinuousPublishPlugin.groovy @@ -2,6 +2,7 @@ package edu.wisc.doit.gradle import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.Task /** * Root Gradle {@link Plugin} class. @@ -19,5 +20,28 @@ class ContinuousPublishPlugin implements Plugin<Project> { project.getTasks() .create("confirmProjectVersionIncremented", ConfirmProjectVersionIncrementedTask.class) + + // findByName can return null; getByName throws UnknownTaskException + configureManifest(project.getTasks().findByName("jar")) + configureManifest(project.getTasks().findByName("war")) + } + + /** + * Set 'Implementation-Title' and 'Implementation-Version' attributes + * in the task's manifest + * + * See https://docs.oracle.com/javase/tutorial/deployment/jar/packageman.html + * + * @param task the task to configure (null safe) + */ + void configureManifest(Task task) { + task?.configure { + manifest { + attributes( + 'Implementation-Title': project.name, + 'Implementation-Version': project.version + ) + } + } } } diff --git a/src/test/groovy/edu/wisc/doit/gradle/ContinuousPublishPluginTest.groovy b/src/test/groovy/edu/wisc/doit/gradle/ContinuousPublishPluginTest.groovy index 65f2fef25cb2b1c763fcd3330736a27f3dd607f7..74ddd25f4ebe90f9ec34999f038a6d652acee42e 100644 --- a/src/test/groovy/edu/wisc/doit/gradle/ContinuousPublishPluginTest.groovy +++ b/src/test/groovy/edu/wisc/doit/gradle/ContinuousPublishPluginTest.groovy @@ -15,6 +15,15 @@ class ContinuousPublishPluginTest { @Test public void pluginAddsTaskToProject() { + Project project = ProjectBuilder.builder().build() + project.pluginManager.apply 'java' + project.pluginManager.apply 'edu.wisc.doit.gradle.continuous-publish-plugin' + + assertTrue(project.tasks.confirmProjectVersionIncremented instanceof ConfirmProjectVersionIncrementedTask) + } + + @Test + public void plugin_still_initializes_if_neither_java_or_war_plugin_present() { Project project = ProjectBuilder.builder().build() project.pluginManager.apply 'edu.wisc.doit.gradle.continuous-publish-plugin'