Un problema habitual en Maven son las dependencias heredadas de otras dependencias, especialmente cuando queremos evitar añadir un .jar concreto. Para solucionar este problema tenemos 2 herramientas sencillas y rápidas.
Con 'mvn dependency:tree' podemos saber que dependencias están importando nuestras dependencias. A continuación debemos añadir una nueva entrada en las '<exclusions>' de nuestra dependencia.
Para evitar que en un futuro vuelva a aparecer dicha dependencia, podemos usar el plugin siguiente:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-version</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<!-- exclude all versions lower than 1.2.17-->
<exclude>log4j:log4j:[0.0,1.2.17)</exclude>
</excludes>
</bannedDependencies>
</rules>
</configuration>
</execution>
</executions>
</plugin>
con este plugin se obtiene un error cuando se esta detectando una dependencia rechazada.
______________________________________________
A common problem with Maven is to know what dependencies are being imported by our own dependencies, especially when we try to avoid a particular .jar file. This problem is esasily solved with two tools.
'mvn dependency:tree' allows us to know all the dependencies imported and which one imports another one. Adding a new entry in '<exclusions>' section of this dependency, we avoid the corresponding file.
To force that in a future this dependency will not be impoerted again, we can use the following plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-version</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<!-- exclude all versions lower than 1.2.17-->
<exclude>log4j:log4j:[0.0,1.2.17)</exclude>
</excludes>
</bannedDependencies>
</rules>
</configuration>
</execution>
</executions>
</plugin>
With this plugin you get an error when this dependency is detected again.
No hay comentarios:
Publicar un comentario