i'm in the process of evaluating maven for building a company software. The special case i have is that all artifacts that are allowed to be used in production are restricted.
The approved libraries are maintained i a special repositoy (in a Artifactory instance).
While the final product is restricted we may use more dependencies for building (maven plugins and their dependencies have lesser restrictions).
So i configured the repository
section in the pom and the pluginRepository
.
The problem is now that all resolved artifacts (for the plugins and for the project) are cached in only one local repository/folder. If someone accidently adds a compile dependency to any of the projects that is only in the cache because of a maven-plugin it will be used without any warning.
I deleted the local repository and recompiled the tested project and the build failed as expected with a unresolveable dependency.
I've searched the web and didn't find a specific answer to this question. There is a pending request on maven to separate the local caches for each repository, but that seems to be only in reviewed for maven 4 state: https://cwiki.apache.org/confluence/display/MAVEN/Local+Repository+Separation
https://issues.apache.org/jira/browse/MNG-3655 https://issues.apache.org/jira/browse/MNG-4302
The maven-enforcer-plugin has kind of a concept here with bannedDependencies, but this requires a extensive configuration to begin with and idealy i'd like to keep up with the currently approved releases without manual interactions.
Any ideas on that? Did i miss a configuration?
Update1:
Well even trying to list all allowed dependencies in the enforcer plugin didn't work for me:
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.2</version>
</dependency>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>*:*</exclude>
</excludes>
<includes>
<include>commons-io:commons-io:1.4</include>
...
</includes>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
The Build should fail here but is [INFO] BUILD SUCCESS
.
Update 2:
What is even more suprising is that in the maven documentation the issue is already adressed to be fixed with changes in version 3: https://cwiki.apache.org/confluence/display/MAVEN/Maven+3.x+Compatibility+Notes#Maven3.xCompatibilityNotes-ResolutionfromLocalRepository
Resolution from Local Repository The local repository used by Maven 3.x has been enhanced to keep track from what remote repositories an artifact was resolved from. This information about an artifact's origin is used to ensure builds can only access locally cached artifacts if they have the proper repositories configured. Hence, projects that lack required remote repositories in their POM might fail when being built with Maven 3. This improves reproducibility of a build by eliminating the effects of unintended artifact sharing via the local repository.