2

I'm using the Gradle publishing mechanism that is is still in incubation using the publishing DSL.

    publishing {
        publications {
            mavenJava(MavenPublication) {
                from components.java
                pom.withXml {
                    def parentNode = asNode().appendNode('parent')
                    parentNode.appendNode('groupId', 'org.springframework.boot')
                    parentNode.appendNode('artifactId', 'spring-boot-starter-parent')
                    parentNode.appendNode('version', springBootVersion)
                }
                // BEGIN sourcejar
                artifact sourceJar {
                    classifier "sources"
                }
                // END sourcejar
                artifact sharedTestJar {
                    classifier "sharedtest"
                }
            }
        }

This basically works but as soon as as I'm adding a classifier the repackaged artifact is not deployed anymore. So what configuration do I have to refer to for registering the repackaged artifact for publication?

bootRepackage {
    classifier = 'exec'
}
Martin Ahrer
  • 937
  • 3
  • 15
  • 28

2 Answers2

2

You'll have to add the jar file created by the bootRepackage task as an additional artifact to publish. Unfortunately the bootRepackage task doesn't seem to expose this as a property.

artifact(file("$buildDir/$project.name-$project.version-${bootRepackage.classifier}.jar")) {
    classifier 'exec'
}
Mark Vieira
  • 13,198
  • 4
  • 46
  • 39
  • Had to adjust only a minor thing: artifact(file("$libsDir/$project.name-$project.version- ${bootRepackage.classifier}.jar")) { classifier 'exec' } -- sorry can't get code blocks formatted in comments? – Martin Ahrer Mar 04 '15 at 09:28
  • Didn'rt woirk for me - I got: Didn't work for me(both options): Could not find method artifact() for arguments [/var/workspace/build/my-project-unspecified-null.jar, build_b8ejm5oe5e1nrnc8xnmcspqxz$_run_closure3@4227f732] on root project 'my-project' of type org.gradle.api.Project. – Henning Oct 28 '17 at 14:17
0

You can get the 'sourcesJar' task in order to attach its sources jar artifact for publication using the JavaPluginConvention. It's a long line to achieve that but you end up not hardcoding the artifact filename.

publishing.publications.create('bootJava', MavenPublication).with {
    ...
    artifact project.tasks.getByName(
        project.getConvention().getPlugin(JavaPluginConvention)
            .getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME)
            .getSourcesJarTaskName())
}
Alex
  • 1,313
  • 14
  • 28