2017-09-25 1 views
0

J'ai cherché un outil, qui est capable de vous montrer les dépendances inutilisées. J'ai bientôt trébuché sur la commande maven mvn dependency:analyze. Le problème avec ceci, c'est qu'il détecte souvent les dépendances "inutilisées" qui laissent la construction échouer si manquant.Des résultats incorrects dans la dépendance mvn: analyser

Voici un exemple d'un projet optimisé:

$ mvn dependency:analyze 

[INFO] Building LogfileTool 0.1 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] >>> maven-dependency-plugin:2.8:analyze (default-cli) > test-compile @ LogfileTool >>> 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ LogfileTool --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 1 resource 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ LogfileTool --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 7 source files to C:\Projects\LogfileToolMa\LogfileTool\target\classes 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ LogfileTool --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] skip non existing resourceDirectory C:\Projects\LogfileToolMa\LogfileTool\src\test\resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ LogfileTool --- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] <<< maven-dependency-plugin:2.8:analyze (default-cli) < test-compile @ LogfileTool <<< 
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:analyze (default-cli) @ LogfileTool --- 
[WARNING] Unused declared dependencies found: 
[WARNING] log4j:apache-log4j-extras:jar:1.2.17:compile 
[WARNING] org.projectlombok:lombok:jar:1.16.18:provided 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 

dépendances dans pom.xml

<dependencies> 

<!-- Logger --> 
<dependency> 
    <groupId>log4j</groupId> 
    <artifactId>log4j</artifactId> 
    <version>1.2.17</version> 
</dependency> 
<dependency> 
    <groupId>log4j</groupId> 
    <artifactId>apache-log4j-extras</artifactId> 
    <version>1.2.17</version> 
</dependency> 


<!-- Generating Getter, Setter etc. --> 
<dependency> 
    <groupId>org.projectlombok</groupId> 
    <artifactId>lombok</artifactId> 
    <version>1.16.18</version> 
    <scope>provided</scope> 
</dependency> 

<dependency> 
    <groupId>commons-io</groupId> 
    <artifactId>commons-io</artifactId> 
    <version>2.4</version> 
    <type>jar</type> 
</dependency> 

</dependencies> 

Les paquets utilisés de Lombok sont:

lombok.AccessLevel 
lombok.Data 
lombok.Getter 
lombok.Setter 

En supprimant lombok de mon POM je reçois l'erreur suivante par Buildig le projet

------------------------------------------------------------- 
COMPILATION ERROR : 
------------------------------------------------------------- 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[7,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[8,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[9,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[10,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[26,2] cannot find symbol 
    symbol: class Data 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[13,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[14,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[15,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[16,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[26,2] cannot find symbol 
    symbol: class Data 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[34,4] cannot find symbol 
    symbol: class Getter 
    location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileSearchConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[35,4] cannot find symbol 
    symbol: class Setter 
    location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileSearchConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[35,4] cannot find symbol 
    symbol: class Getter 
    location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileParseConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[36,4] cannot find symbol 
    symbol: class Setter 
    location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileParseConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[62,7] cannot find symbol 
    symbol: method setXmlToRead(java.lang.String) 
    location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileSearchConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[63,7] cannot find symbol 
    symbol: method setPathToLogfiles(java.lang.String) 
    location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileSearchConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[63,7] cannot find symbol 
    symbol: method setPathForStorage(java.lang.String) 
    location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileParseConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[64,7] cannot find symbol 
    symbol: method setPathToLogfile(java.lang.String) 
    location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileParseConfig 
ch/glue/logfiletool/logfiletool/log_handler/LogfileReader.java:[93,50] cannot find symbol 
    symbol: method getPathToLogfiles() 
    location: variable logfileSearchConfig of type ch.glue.logfiletool.logfiletool.config_handler.LogfileSearchConfig 
ch/glue/logfiletool/logfiletool/log_handler/LogfileReader.java:[95,100] cannot find symbol 
    symbol: method getXmlToRead() 
    location: variable logfileSearchConfig of type ch.glue.logfiletool.logfiletool.config_handler.LogfileSearchConfig 
ch/glue/logfiletool/logfiletool/Main.java:[61,51] cannot find symbol 
    symbol: method getPathToLogfile() 
    location: variable logfileToolConfig of type ch.glue.logfiletool.logfiletool.config_handler.LogfileParseConfig 
ch/glue/logfiletool/logfiletool/Main.java:[71,52] cannot find symbol 
    symbol: method getPathForStorage() 
    location: variable logfileToolConfig of type ch.glue.logfiletool.logfiletool.config_handler.LogfileParseConfig 
22 errors 
------------------------------------------------------------- 
------------------------------------------------------------------------ 
BUILD FAILURE 
------------------------------------------------------------------------ 
Total time: 1.747 s 
Finished at: 2017-09-27T10:04:20+02:00 
Final Memory: 14M/210M 
------------------------------------------------------------------------ 
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project LogfileTool: Compilation failure: Compilation failure: 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[7,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[8,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[9,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[10,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[26,2] cannot find symbol 
symbol: class Data 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[13,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[14,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[15,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[16,14] package lombok does not exist 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[26,2] cannot find symbol 
symbol: class Data 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[34,4] cannot find symbol 
symbol: class Getter 
location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileSearchConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[35,4] cannot find symbol 
symbol: class Setter 
location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileSearchConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[35,4] cannot find symbol 
symbol: class Getter 
location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileParseConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[36,4] cannot find symbol 
symbol: class Setter 
location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileParseConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[62,7] cannot find symbol 
symbol: method setXmlToRead(java.lang.String) 
location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileSearchConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileSearchConfig.java:[63,7] cannot find symbol 
symbol: method setPathToLogfiles(java.lang.String) 
location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileSearchConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[63,7] cannot find symbol 
symbol: method setPathForStorage(java.lang.String) 
location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileParseConfig 
ch/glue/logfiletool/logfiletool/config_handler/LogfileParseConfig.java:[64,7] cannot find symbol 
symbol: method setPathToLogfile(java.lang.String) 
location: class ch.glue.logfiletool.logfiletool.config_handler.LogfileParseConfig 
ch/glue/logfiletool/logfiletool/log_handler/LogfileReader.java:[93,50] cannot find symbol 
symbol: method getPathToLogfiles() 
location: variable logfileSearchConfig of type ch.glue.logfiletool.logfiletool.config_handler.LogfileSearchConfig 
ch/glue/logfiletool/logfiletool/log_handler/LogfileReader.java:[95,100] cannot find symbol 
symbol: method getXmlToRead() 
location: variable logfileSearchConfig of type ch.glue.logfiletool.logfiletool.config_handler.LogfileSearchConfig 
ch/glue/logfiletool/logfiletool/Main.java:[61,51] cannot find symbol 
symbol: method getPathToLogfile() 
location: variable logfileToolConfig of type ch.glue.logfiletool.logfiletool.config_handler.LogfileParseConfig 
ch/glue/logfiletool/logfiletool/Main.java:[71,52] cannot find symbol 
symbol: method getPathForStorage() 
location: variable logfileToolConfig of type ch.glue.logfiletool.logfiletool.config_handler.LogfileParseConfig 
-> [Help 1] 

To see the full stack trace of the errors, re-run Maven with the -e switch. 
Re-run Maven using the -X switch to enable full debug logging. 

For more information about the errors and possible solutions, please read the following articles: 
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 

Et sans log4j-extras i get suivantes erreur en exécutant le projet

log4j:ERROR Could not instantiate class [org.apache.log4j.rolling.RollingFileAppender]. 
java.lang.ClassNotFoundException: org.apache.log4j.rolling.RollingFileAppender 

Les deux log4j et lombok sont utilisés dans mon projet. Avez-vous une idée pour résoudre ce problème ou d'où cela vient-il?

vous remercie à l'avance

+1

La première chose à faire est d'utiliser une version plus récente de [maven-dependency-plugin] (https://maven.apache.org/plugins/maven-dependency-plugin/). En outre, la question est de savoir comment ces dépendances sont utilisées? – khmarbaise

+1

Je crois que l'analyseur fonctionne au niveau du bytecode donc il peut ne pas détecter quelque chose comme lombok étant inutilisé car il est déjà compilé. –

+0

Avez-vous essayé de modifier les portées? Log4j-extras peut-il être une dépendance d'exécution? Je ne suis pas familier avec lombok et comment cela pourrait être résolu –

Répondre

0

Je suis également en cours d'exécution dans la question où projet Lombok a été marquée par dependency:analyze comme une dépendance déclarée non utilisée. Le projet Lombok fait la majeure partie de son temps de compilation magique et, de ce fait, la plupart des annotations sont supprimées après la compilation. C'est pourquoi l'analyseur de dépendances de Maven ne le reconnaît pas. Et pourquoi il ne parvient pas non plus à détecter les dépendances qui sont chargées en utilisant SPI.

Nous avons travaillé autour de cela en disant explicitement au plugin de l'analyseur de dépendance d'ignorer le projet Lombok. Cela peut être fait avec l'option de configuration <usedDependency> ou plus à grains fins <ignoreUnusedDeclaredDependency> en tant que tel:

<pluginManagement> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>3.0.2</version> 
      <configuration> 
       <ignoredUnusedDeclaredDependencies> 
        <ignoredUnusedDeclaredDependency>org.projectlombok:lombok</ignoredUnusedDeclaredDependency> 
       </ignoredUnusedDeclaredDependencies> 
      </configuration> 
     </plugin> 
    </plugins> 
</pluginManagement> 

PS en ce qui concerne les étendues: Lombok est une dépendance de compilation, mais n'a pas besoin d'être sur le chemin de classe lors de l'exécution (ou à la fin dans votre dossier lib). La dépendance provided indique que le fichier jar doit être présent pour la compilation, mais lors de l'exécution, il doit être fourni par l'environnement d'exécution (par exemple, le conteneur dans lequel vous l'exécutez). Comme Lombok n'est pas nécessaire au moment de l'exécution, il n'y aura pas de problèmes lorsque votre runtime ne fournira pas Lombok, contrairement à ce que vous attendez de la déclaration de dépendance Maven.