I’m trying to manipulate the maven pom before it is generated, and having some trouble accessing the maven classes. Specificially, I want to manually add some excludes to the pom (I know I can do this through gradle dependencies, but it doesn’t quite work for what I need). So I have some code like this (not exact, just for demonstration):
project.modifyPom { MavenPom pom ->
for (org.apache.maven.model.Dependency dep : pom.dependencies) {
org.apache.maven.model.Exclusion exclude = new org.apache.maven.model.Exclusion()
exclude.setGroupId(depToExclude.group)
exclude.setArtifactId(depToExclude.name)
dep.addExclusion(exclude)
}
}
However, running say gradle install
I get a class not found exception:
Caused by: java.lang.ClassNotFoundException: org.apache.maven.model.Dependency
... 108 more
Similarly, if I change the assignment in the for loop to a def, I get a class not found for Exclusion
. So it seems the maven classes are not accessible. Looking a little closer at MavenPom, it looks clear it was designed as to not leak the implementation detail (using Maven classes to generate the pom). However, the fact that you can setDependencies means one needs access to the actual concrete type of the dependencies list. Am I missing something? Is there another way I can add an exclude at pom generation (hopefully other than adding the xml myself in withXml
)?