Hello,
I am new to Gradle and currently trying to create a multi-module skeleton as a base to transform my old maven projects. I am trying to use the maven-publish plugin to generate pom-files to be uploaded to a maven repo and to be used locally for users who might want to build the project with maven instead of gradle.
For example I have the directory api in which I would like to generate an aggregate pom that lists each subdirectory inside this api-directory as a module but don’t know how to achieve that automatically (without adding an entry for each module to the generator configuration).
Here is my current build.gradle:
allprojects {
group = 'hello'
version = '0.0.1-SNAPSHOT'
}
subprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
repositories {
mavenCentral()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.25'
compile 'org.apache.commons:commons-lang3:3.6'
compileOnly 'com.google.code.findbugs:jsr305:3.0.1'
testCompileOnly 'com.google.code.findbugs:jsr305:3.0.1'
testCompile 'junit:junit:4.12'
}
publishing {
publications {
mavenJava(MavenPublication) {
from project.components.java
pom.withXml {
asNode().appendNode("name", project.name)
asNode().appendNode("description", project.description)
}
}
/*
mavenClassesJar(MavenPublication) {
from components.java
artifact(sourcesJar) {
classifier = 'sources'
}
artifact(javadocJar) {
classifier = 'javadoc'
}
}
*/
}
}
model {
tasks.generatePomFileForMavenJavaPublication {
destination = file("pom.xml")
}
}
}
project(':common:model') {
}
project(':api:remote-api') {
description = "Description of the remote api..."
dependencies {
compileOnly project(':common/model')
}
publishing {
publications {
mavenJava(MavenPublication) {
pom.withXml {
}
}
}
}
}
project(':api') {
dependencies {
compileOnly project(':api:frontend-api')
compileOnly project(':api:remote-api')
}
}
project(':runtime') {
dependencies {
compile project(':api')
}
}
And my settings.gradle:
rootProject.name = 'my-example-architecture'
include 'common:model'
include 'api:frontend-api'
include 'api:remote-api'
include 'api'
include 'runtime'
What I want to achieve should look similar to this one:
/api/pom.xml:
…
<groupId>hello</groupId>
<artifactId>api</artifactId>
<packaging>pom</packaging>
<modules>
<module>remote-api</module>
<module>frontend-api</module>
…
</modules>
So for each module/project in the api-directory there should be an module-entry in the pom.xml but currently this doesn’t get generated. So if a user decides to build the whole stuff with maven it would be neccessary to walk through the directories and run mvn on each pom.xml file manually. Is there any solution/workaround for this or is it so unusual trying to make a setup with an automatic co-existence of gradle and maven?