2

In order to not manually manage, both, Maven and Gradle build configuration files, I wanted to let Gradle generate the Maven POMs for a multi-module build.

This is working so far. Below you find the settings.gradle

rootProject.name = 'parent'
include 'module-a'  
include 'module-b'

and here follows build.gradle

allprojects  {
    apply plugin: 'maven'

    group = 'com.example.project'
    version = '1.0-SNAPSHOT'
}

subprojects {
    apply plugin: 'java'

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    repositories {
        mavenCentral()
    }

    task createPom << {
        pom {
            project {
                parent {
                    groupId project.group
                    artifactId rootProject.name
                    version project.version
                }
            }
        }.writeTo("pom.xml")
    }
}

task createPom << {
    pom {
        project {
            packaging 'pom'
            modules {
                module 'module-a'
                module 'modula-b'
            }
        }
    }.writeTo("pom.xml")
}

The problem is that I have to manually declare the modules in the createPom task of the root project. Also, I need two dedicated tasks; one for the root project and and for the subprojects.

How can I let Gradle figure out what the modules are? Or is there a way to programmatically determine and add the subprojects as modules? Furthermore, is it even necessary to have two distinct tasks?

mike
  • 4,929
  • 4
  • 40
  • 80

0 Answers0