I have a Gradle project which uses Spring's dependency management plugin to define a list of dependency versions. I am also using the Maven plugin to deploy the project to a Maven repository.
I would like to be able to deploy this as a Maven bill of materials (BOM) so that I can use it in other Gradle projects to define my dependency versions. I have been able to get this to work so long as I also deploy a JAR file. However, the JAR is completely empty and superfluous. My goal is to generate and deploy just the POM file, like I would be able to do if this were a Maven project with a "pom" packaging.
If I manually exclude the JAR from the list of artifacts to be published, then nothing gets installed, not even the POM file.
This is a test build to demonstrate the issue:
group 'test'
version '1.0.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE' //Matches the Spring IO version
}
}
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven'
dependencyManagement {
dependencies {
dependency 'cglib:cglib-nodep:3.2.4'
dependency 'junit:junit:4.12'
}
}
////Uncommenting this causes nothing at all to be deployed:
//jar.enabled = false
//configurations.archives.artifacts.with { archives ->
// archives.removeAll { it.type == 'jar' }
//}
The above correctly produces and installs the following POM file into my local Maven repo:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>gradle-pom-packaging-test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
However, it also installs a JAR file that is empty save for the MANIFEST.MF file.
I was able to successfully get this working using the maven-publish
plugin. However, I'm also making use of the Gradle Sonatype Nexus plugin to publish the artifact to a Nexus instance. As this builds upon the maven
plugin, the maven-publish
plugin will not work for my needs. The following is all I needed to add to get it working with the maven-publish
plugin:
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
}
}
}
Is there a way to generate and deploy just the POM file using the maven
Gradle plugin, like I would be able to do if this were a Maven project with a "pom" packaging?