9

When I build a spring-boot application (to a standalone jar) using gradle build, the proper artifacts are generated. The resulting jar contains all dependent jars and is executable.

I have also configured the maven-publish plugin as follows:

publishing {
   publications {
      mavenJava(MavenPublication) {
         from components.java
      }
   }
}

Now when I execute gradle publish, a much smaller jar without dependencies gets build and published.

Following steps are not executed in the latter case.

:myProject:bootRepackage                                                                        
:myProject:assemble

How can I make sure the correct build steps are executed when publishing?

bertvh
  • 821
  • 1
  • 7
  • 17

1 Answers1

22

I'm a little surprised that publishing from components.java doesn't trigger the Java plugin's assemble task. Spring Boot's bootRepackage task is setup as a dependency of the assemble task so you'll need to cause publish to run assemble. Try adding the following to your build.gradle:

publish {
    dependsOn assemble
} 
Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • 1
    The reason being is that the Java plugin simply adds the result of the `jar` task to the component collection. It would be the responsibility of the Spring Boot plugin to modify this to be the repackaged jar. That said, one could argue that what get's published should in fact just be the plain jar and that the repacked jar should probably be published under a unique classifier. – Mark Vieira Oct 06 '14 at 16:40
  • 1
    That's a good suggestion, thanks. Rather than treating the repackaged jar as a separate artifact, Spring Boot currently transforms the output from the jar task in place. I'm now wondering if that should also be changed so that both the original artifact and the repackaged artifact can be referred to within the Gradle build. I've opened https://github.com/spring-projects/spring-boot/issues/1666. – Andy Wilkinson Oct 06 '14 at 16:48
  • Assigning a classifier on the repackaged jar is [already supported](http://docs.spring.io/spring-boot/docs/1.1.7.RELEASE/reference/htmlsingle/#build-tool-plugins-gradle-repackage-configuration). Just add `bootRepackage { classifier = 'boot' }. – Mark Vieira Oct 06 '14 at 16:54
  • I was referring to making the repackaged artifact available in the build, for example by including it in project.configurations.archives.allArtifacts – Andy Wilkinson Oct 06 '14 at 17:09