siom79 / japicmp

Comparison of two versions of a jar archive
https://siom79.github.io/japicmp
Apache License 2.0
712 stars 107 forks source link

[japicmp-maven-plugin] Optional and provided dependencies not resolved correctly #224

Closed sebthom closed 5 years ago

sebthom commented 5 years ago

When having a provided dependency in a project, like e.g.

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.4</version>
    <scope>provided</scope>
</dependency>

running japicmp-maven-plugin fails with:

[ERROR] Failed to execute goal com.github.siom79.japicmp:japicmp-maven-plugin:0.13.0:cmp (cmp@package) on project my-project: Execution cmp@package of goal com.github.siom79.japicmp:japicmp-maven-plugin:0.13.0:cmp failed: Could not load 'javax.servlet.ServletException': javax.servlet.ServletException. Please make sure that all libraries have been added to the classpath (CLASSPATH=<SNIP>) or try the option '--ignore-missing-classes'. -> [Help 1]

Same is true for optional dependencies:

<dependency>
     <groupId>com.google.guava</groupId>
     <artifactId>guava</artifactId>
     <version>27.0-jre</version>
     <optional>true</optional>
</dependency>

running japicmp-maven-plugin fails with:

[ERROR] Failed to execute goal com.github.siom79.japicmp:japicmp-maven-plugin:0.13.0:cmp (cmp@package) on project my-project: Execution cmp@package of goal com.github.siom79.japicmp:japicmp-maven-plugin:0.13.0:cmp failed: Could not load 'com.google.common.cache.CacheLoader': com.google.common.cache.CacheLoader. Please make sure that all libraries have been added to the classpath (CLASSPATH=<SNIP>) or try the option '--ignore-missing-classes'. -> [Help 1]

Having to enable --ignore-missing-classes for optional/provided dependencies should not be required, as these dependencies are actually on the compile classpath.

siom79 commented 5 years ago

I have created a sample project but was not able to reproduce your issue. The pom.xml file looks like this:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>test</artifactId>
    <version>0.0.2-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>27.0-jre</version>
            <optional>true</optional>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>com.github.siom79.japicmp</groupId>
                <artifactId>japicmp-maven-plugin</artifactId>
                <version>0.13.0</version>
                <configuration>
                    <newVersion>
                        <file>
                            <path>${project.build.directory}/${project.artifactId}-${project.version}.${project.packaging}</path>
                        </file>
                    </newVersion>
                    <parameter>
                        <ignoreMissingOldVersion>true</ignoreMissingOldVersion>
                    </parameter>
                </configuration>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>cmp</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

The App class implements the Servlet interface:

public class App implements Servlet {
    public static void main(String[] args) {
        Stopwatch stopwatch = Stopwatch.createStarted();
        stopwatch.stop();
    }
    // implemented interface methods removed
}

The build is successful and the file target/japicmp/japicmp.diff contains the following:

Comparing source compatibility of D:\projekte\tmp\example\target\test-0.0.2-SNAPSHOT.jar against C:\MCP-IDE\repository\com\example\test\0.0.1\test-0.0.1.jar
===  UNCHANGED CLASS: PUBLIC com.example.App  (not serializable)
    ===  CLASS FILE FORMAT VERSION: 49.0 <- 49.0
    ===  UNCHANGED INTERFACE: javax.servlet.Servlet
    ===  UNCHANGED CONSTRUCTOR: PUBLIC App()
    ===  UNCHANGED METHOD: PUBLIC void destroy()
    ===  UNCHANGED METHOD: PUBLIC javax.servlet.ServletConfig getServletConfig()
    ===  UNCHANGED METHOD: PUBLIC java.lang.String getServletInfo()
    ===  UNCHANGED METHOD: PUBLIC void init(javax.servlet.ServletConfig)
        ===  UNCHANGED EXCEPTION: javax.servlet.ServletException
    ===  UNCHANGED METHOD: PUBLIC STATIC void main(java.lang.String[])
    ===  UNCHANGED METHOD: PUBLIC void service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
        ===  UNCHANGED EXCEPTION: javax.servlet.ServletException
        ===  UNCHANGED EXCEPTION: java.io.IOException

Can you share more details about your configuration?

sebthom commented 5 years ago

Thanks for your quick response.

We experience the issue locally on Windows 7 with OpenJDK 1.80u191 and Maven 3.6 as well as on Jenkins CI with Ubuntu 16.04, OracleJDK 1.8u181 and Maven 3.5.3.

I'll see if I can strip down the project configuration to isolate the issue.

siom79 commented 5 years ago

Please open again if necessary.

sundeep-paulraj commented 5 years ago

Waiting for Jenkins to finish collecting data [ERROR] Failed to execute goal com.github.siom79.japicmp:japicmp-maven-plugin:0.13.1:cmp (default) on project core: Please provide at least one resolvable old version using one of the configuration elements or . -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException [JENKINS] Archiving /var/lib/jenkins/workspace/MPD/DEVOPS/Hygieia-Core/pom.xml to com.capitalone.dashboard/core/3.1.2-SNAPSHOT/core-3.1.2-SNAPSHOT.pom [JENKINS] Archiving /var/lib/jenkins/workspace/MPD/DEVOPS/Hygieia-Core/target/core-3.1.2-SNAPSHOT.jar to com.capitalone.dashboard/core/3.1.2-SNAPSHOT/core-3.1.2-SNAPSHOT.jar channel stopped Finished: FAILURE

siom79 commented 5 years ago

Can you please post your configuration? Looks like you don't have provided an old version.

Am Fr., 28. Juni 2019, 05:43 hat Sundeep Kumar Paulraj < notifications@github.com> geschrieben:

Waiting for Jenkins to finish collecting data [ERROR] Failed to execute goal com.github.siom79.japicmp:japicmp-maven-plugin:0.13.1:cmp (default) on project core: Please provide at least one resolvable old version using one of the configuration elements or . -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException [JENKINS] Archiving /var/lib/jenkins/workspace/MPD/DEVOPS/Hygieia-Core/pom.xml to com.capitalone.dashboard/core/3.1.2-SNAPSHOT/core-3.1.2-SNAPSHOT.pom [JENKINS] Archiving /var/lib/jenkins/workspace/MPD/DEVOPS/Hygieia-Core/target/core-3.1.2-SNAPSHOT.jar to com.capitalone.dashboard/core/3.1.2-SNAPSHOT/core-3.1.2-SNAPSHOT.jar channel stopped Finished: FAILURE

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/siom79/japicmp/issues/224?email_source=notifications&email_token=AA4U7NDKO2OWNPRC4JOPRJDP4WCHDA5CNFSM4GHOPATKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYY642I#issuecomment-506588777, or mute the thread https://github.com/notifications/unsubscribe-auth/AA4U7NHKZY3PS6QTSWPDIRLP4WCHDANCNFSM4GHOPATA .