Description
According to issue 19609 and 47a6865
, generation of Gradle metadata when publishing to a Maven repository, is restored.
However, when using Gradle 6.7, given a simplest Spring Boot application (from start.spring.io) with the maven-publish
plugin slapped on top, the Gradle Metadata is not generated automatically:
build.gradle
plugins {
id 'org.springframework.boot' version '2.3.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id 'maven-publish'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
publishing {
repositories {
mavenLocal()
}
publications {
bootJava(MavenPublication) {
artifact bootJar
}
}
}
The output of ./gradlew publish --console verbose
:
> Task :compileJava
> Task :processResources
> Task :classes
> Task :bootJar
> Task :generatePomFileForBootJavaPublication
> Task :publishBootJavaPublicationToMavenLocalRepository
> Task :publish
BUILD SUCCESSFUL in 1s
5 actionable tasks: 5 executed
Note the lack of the generateMetadataFileForBootJavaPublication
task. Consequently, there is no Gradle metadata in the maven repository. I tried different versions of Gradle and Spring Boot. Went back to Gradle 6.2 and Spring Boot 2.3.0.M3 — but still couldn’t get it to work.
To contrast, if we remove the Spring Boot plugin, the output is:
> Task :compileJava
> Task :processResources
> Task :classes
> Task :jar
> Task :generateMetadataFileForBootJavaPublication
> Task :generatePomFileForBootJavaPublication
> Task :publishBootJavaPublicationToMavenLocalRepository
> Task :publish
BUILD SUCCESSFUL in 695ms
6 actionable tasks: 6 executed
The generateMetadataFileForBootJavaPublication
task is there, as it should be.
Steps to reproduce
Download gradle-metadata-is-not-generated.zip. Then run:
$ unzip gradle-metadata-is-not-generated.zip && cd gradle-metadata-is-not-generated
$ ./gradlew publish --console verbose
Just in case, also attaching the project that does create metadata (with Spring Boot plugin disabled): gradle-metadata-is-generated.zip.
Comment From: wilkinsona
Thanks for the sample. The problem is with how you have declared the publication. If you run the generateMetadataFileForBootJavaPublication
task, Gradle will skip it and tells you why it has done so:
./gradlew generateMetadataFileForBootJavaPublication
> Task :generateMetadataFileForBootJavaPublication SKIPPED
Maven publication 'bootJava' isn't attached to a component. Gradle metadata only supports publications with software components (e.g. from component.java)
BUILD SUCCESSFUL in 932ms
You probably want to either declare a new component or add bootJar
as a variant to the Java component. You can learn more about customizing publishing in Gradle's documentation.