ASSERT-KTH/depclean

[BUG] Does not work if dependencies are snapshots

alerosmile opened this issue · 5 comments

Describe the bug
Snapshot dependencies are missing from the JSON report. This is probably due to the difference between Artifact.getVersion() and Artifact.getBaseVersion(). depclean uses Artifact.getVersion() but that doesn't match the output of mvn dependency:tree which uses Artifact.getBaseVersion().

Expected behavior
Snapshot dependencies should be included in the JSON report.

Hi @alerosmile, thanks for reporting this issue.

I've added a dependency with SNAPSHOT version to the project json_should_be_correct. This project is used by DepClean for integration test. I checked the depclean-results.json produced, and it is correct (i.e., it lists all the types in the SNAPSHOT dependency that I just added).

Can you provide more context on this issue or give an example of a project for which DepClean produces an incorrect depclean-results.json file?

I've added the following SNAPSHOT dependency:

<repositories>
  <repository>
    <id>apache.snapshots</id>
    <url>https://repository.apache.org/snapshots/</url>
    <releases>
      <enabled>false</enabled>
    </releases>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
  </repository>
</repositories>
<dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-javadoc-plugin</artifactId>
  <version>3.4.2-SNAPSHOT</version>
</dependency>

The dependency is not added to the JSON. It is added if the dependency was maven-javadoc-plugin:3.4.1.

The log output with 3.4.1 is:

POTENTIALLY UNUSED DIRECT DEPENDENCIES [2]: 
	org.apache.maven.plugins:maven-javadoc-plugin:3.4.1:compile (511 KB)

The content of tree.txt is:

org.foo.bar:foobar:jar:1.0.0-SNAPSHOT
+- com.jcabi:jcabi-manifests:jar:1.1:compile
+- commons-io:commons-io:jar:2.8.0:compile
+- commons-codec:commons-codec:jar:1.15:compile
\- org.apache.maven.plugins:maven-javadoc-plugin:jar:3.4.1:compile

The log output with 3.4.2-SNAPSHOT is:

POTENTIALLY UNUSED DIRECT DEPENDENCIES [2]: 
	org.apache.maven.plugins:maven-javadoc-plugin:3.4.2-20221217.222016-23:compile (486 KB)

The content of tree.txt is:

org.foo.bar:foobar:jar:1.0.0-SNAPSHOT
+- com.jcabi:jcabi-manifests:jar:1.1:compile
+- commons-io:commons-io:jar:2.8.0:compile
+- commons-codec:commons-codec:jar:1.15:compile
\- org.apache.maven.plugins:maven-javadoc-plugin:jar:3.4.2-SNAPSHOT:compile

Here you can see the difference: 3.4.2-20221217.222016-23 vs. 3.4.2-SNAPSHOT.

Have a look at se.kth.depclean.core.analysis.model.ProjectDependencyAnalysis.findByCoordinates(String):
dependencyClassesMap's key is org.apache.maven.plugins:maven-javadoc-plugin:3.4.2-20221217.222016-23 but coordinate is org.apache.maven.plugins:maven-javadoc-plugin:3.4.2-SNAPSHOT.

Here are screenshots of the results:
image

image

What am I doing differently than you?

Hi @alerosmile,
You're right. Using Artifact.getBaseVersion() instead of Artifact.getVersion() fixes the issue. I merged a PR to the master branch: #147

Please install the latest version of Depclean:

https://github.com/castor-software/depclean.git
cd depclean
mvn clean install -DskipTests

Then run DepClean on your project as follows:

mvn se.kth.castor:depclean-maven-plugin:2.0.4-SNAPSHOT:depclean -DcreateResultJson=true

Let me know if the generated file depclean-results.json contains the information of all the dependencies now.

Hi @cesarsotovalero,

Sorry for the late response. The bugfix works, but it was reverted in 462bca1.

MavenDebloater still doesn't work. getVersion() should be replaced with getBaseVersion() in matches(Artifact, Dependency) and createDependency(Artifact).

For this to reproduce you have to make sure that the maven-javadoc-plugin from my example above is actually used (adding import org.apache.maven.plugins.javadoc.JavadocJar; should be enough)

I'm not sure about MavenDependencyGraph.projectCoordinates()...