How to remove some of the dependencies when generating a pom using maven plugin?


(Dhananjay Nene) #1

I am creating a fatJar which includes classes from many other jar dependencies into the jar being assembled. As a result I need to exclude some (not all) dependencies when the .pom file is generated. The following code (slightly modified) from the maven plugin page allows me to mark these jars as optional. How would I remove them from the dependencies or mark them in a fashion that they do not appear in the generated pom ?

The group Id / artifactId below are merely indicative. I have a list of them.

install.repositories.mavenInstaller.pom.whenConfigured {pom ->

pom.dependencies.find {dep -> dep.groupId == ‘org.scala-lang’ && dep.artifactId == ‘scala-compiler’ }.optional = true }


(Dhananjay Nene) #2

With some further effort was able to resolve the same. eg. to remove all dependencies from appearing in the generated .pom the following worked :

install.repositories.mavenInstaller.pom.whenConfigured {pom ->

deps = project.configurations[‘compile’].dependencies.collect {dep ->[dep.group,dep.name]}

pom.dependencies.removeAll {dep -> deps.contains([dep.groupId,dep.artifactId])} }

(* code might suck … my groovy skills are still quite limited *)


(Luke Daley) #3

Unless you are changing the configuration → scope mappings, you can do this:

pom.dependencies.removeAll { it.scope == "compile" }

Side note: when posting code to the forums, it’s a good idea to wrap the code in…

<code> «your code here» </code>

This gives you syntax highlighting and preservation of whitespace.