Slackbot
12/06/2022, 3:20 PMFrançois Guillot
12/07/2022, 7:18 AMFrançois Guillot
12/07/2022, 1:02 PMparent project
sub1 (packaging pom)
declares a few compile dependencies
sub2 (packaging jar)
declares a dependency on sub1 with type = pom
has a few tests
When running mvn clean install, all is good, and I can see that the transitive dependencies declared in sub1 are also present on e.g. the compile classpath of sub2, as transitive dependencies of the sub1 pom.
Then, I changed the sub1 pom a bit, by adding a fake <properties><foo>bar</foo></properties>, and as you mentioned, the test goal is not taken from cache anymore. The comparison shows a difference in the testClasspathElements file property, where sub1/pom.xml is different.
So I guess I reproduced it properly.
Then, I tried declaring a runtime classpath normalization on sub2 pom
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.gradle</groupId>
<artifactId>gradle-enterprise-maven-extension</artifactId>
<configuration>
<gradleEnterprise>
<normalization>
<runtimeClassPath>
<ignoredFiles>
<ignoredFile>**/pom.xml</ignoredFile>
</ignoredFiles>
</runtimeClassPath>
</normalization>
</gradleEnterprise>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
and this didn’t work.
I debugged it and this kind of normalization only works for files inside elements on the runtime class path. (e.g. a foo.jar that contains a path/to/pom.xml file would be normalized withtout this pom.xml file). You cannot filter out classpath elements like that.
I also tried to use https://maven.apache.org/surefire/maven-surefire-plugin/examples/configuring-classpath.html#removing-dependency-classpath-elements to remove this pom.xml from the surefire classpath, but this doesn’t seem to work for ‘pom’ dependencies :/
Have you considered using dependencyManagement in the parent project, to declare your dependencies (with their versions, etc), and only declare them via dependencies (without version) in the child modules ? You would still have to declare the dependencies in all consuming modules (like here ‘sub2’) instead of centralizing them in ‘sub1’, but just with their groupId+artifactId.
Or, you can live with the ‘packing jar’ approach, maybe ? With this approach, the sub1 pom.xml is not added to the classpath, but the (empty) sub1.jar, and also its transitive dependencies.Jörgen Andersson
12/09/2022, 8:11 AMdependencyManagement is not an option in this case (we use it in many other places) since the purpose of the pom-dependency is to group a set of runtime-dependencies that needs to be included in severals pom:s building runtime packages (rpm:s in our case). We don't want to repeat the dependencies in each pom where needed.
Changing from pom-packaging to jar-packaging was the solution we ended up using, but it is a bit of a work-around. In general I can't see any reason why Gradle Enterprise Maven Extension should consider a pom-file on the runtime classpath at all while calculating the cache-key. I can't see how it could possible affect the execution. Maybe that is something you could consider for future updates?François Guillot
12/09/2022, 8:32 AMFrançois Guillot
12/13/2022, 2:01 PMimplementation(group:artifact:version@pom) { transitive = true }
)
and you end up exactly as in your case, with the transitive jars, but also the pom on the runtime classpath.
We are weighing different options here, as to how to best solve this.
Given this is not blocking you (correct me if I’m wrong), we’re going to take a little bit of time to do it right for both build tools.
I’ll try to ping you early next year when I have more news or when we release a new version of the Gradle Enterprise Maven extension that will filter this out.Jörgen Andersson
12/13/2022, 2:19 PM