Without changing project structure, what's the cleanest way to generate more than one artifact+pom.xml combination from a project?

I have a legacy project and I want Gradle to work with it without having to change the way my project is structured. My project needs to output two artifacts, each with it’s own pom.xml. The second artifact uses a subset of the code and a subset of the dependencies.

Right now the best solution I have is to add an additional sibling subproject that duplicates the dependency declarations and specifies srcDir’s pointing at the original source, and include filters to select the subset I need.

The biggest downside here is that I’ve created a duplication of the dependencies, which is creating room for error and confusion in the future.

Without changing project structure, what’s the cleanest way to generate more than one artifact+pom.xml combination from a project?

There is a section in the manual about this:

http://gradle.org/current/docs/userguide/maven_plugin.html#sub:multiple_artifacts_per_project

But it is a little terse.

Have you tried using filters and hit any specific problems?

Thanks for the pointer to the manual, Luke. Going in this direction gets me to here:

  1. When I use one or more pom(name) filters I notice that the “default” artifact is not published, which is good. 2. I can specify another SourceSet and be able to compile it separately from the main, which is also good.

Where I get stuck with this approach is: * How can I specify the subset of compile dependencies of my extra SourceSet in (2) in such a way that they are the only ones included in the pom filter defined in (1)?

How do you declare the dependencies for your additional source set? If you define an additional dependency configuration for it than you just need to configure the pom(‘myOtherArtifact’).scopeMappings object.

See:

http://gradle.org/current/docs/javadoc/org/gradle/api/artifacts/maven/MavenPom.html

http://gradle.org/current/docs/javadoc/org/gradle/api/artifacts/maven/Conf2ScopeMappingContainer.html