Skip to content
Snippets Groups Projects
Commit 300638dc authored by Nicholas Blair's avatar Nicholas Blair
Browse files

Merge branch 'release-version' into 'master'

feat: always populate MANIFEST with project.name and .version

This pull request directs the plugin to configure the `jar` task (if present, provided by the `java` plugin) and/or the `war` task (if present, provided by the `war` plugin) to set the `Implementation-Version` and `Implementation-Title` attributes in the MANIFEST.MF file included in the result.

The end result is that issue #1 can be satisfied by pulling out `Implementation-Version` from the MANIFEST. By using MANIFEST, we use a file in Java specifications and we don't have to pollute the build of downstream projects with our own custom properties file.

Manifest reference:

https://docs.oracle.com/javase/tutorial/deployment/jar/packageman.html

cc: @paul.erickson @apatwary 




See merge request !2
parents 2a0d10e0 161c85a3
No related branches found
No related tags found
1 merge request!2feat: always populate MANIFEST with project.name and .version
......@@ -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:
![Git Publisher configuration screenshot](git-publisher-config.png)
## Developing the plugin
......
// 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),
])
)
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 {
......
git-publisher-config.png

86.2 KiB

......@@ -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
)
}
}
}
}
......@@ -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'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment