siom79 / japicmp

Comparison of two versions of a jar archive
https://siom79.github.io/japicmp
Apache License 2.0
694 stars 107 forks source link
api-documentation api-management change-management change-tracker comparison java

The website is located at https://siom79.github.io/japicmp.

japicmp

japicmp is a tool to compare two versions of a jar archive:

java -jar japicmp-0.22.0-jar-with-dependencies.jar -n new-version.jar -o old-version.jar

It can also be used as a library:

JarArchiveComparatorOptions comparatorOptions = new JarArchiveComparatorOptions();
JarArchiveComparator jarArchiveComparator = new JarArchiveComparator(comparatorOptions);
List<JApiClass> jApiClasses = jarArchiveComparator.compare(oldArchives, newArchives);

japicmp is available in the Maven Central Repository: maven

<dependency>
    <groupId>com.github.siom79.japicmp</groupId>
    <artifactId>japicmp</artifactId>
    <version>0.22.0</version>
</dependency>

A maven plugin allows you to integrate the checks into your build:

<plugin>
    <groupId>com.github.siom79.japicmp</groupId>
    <artifactId>japicmp-maven-plugin</artifactId>
    <version>0.22.0</version>
    <configuration>
        <oldVersion>
            <dependency>
                <groupId>japicmp</groupId>
                <artifactId>japicmp-test-v1</artifactId>
                <version>${oldversion}</version>
                <type>jar</type>
            </dependency>
        </oldVersion>
        <newVersion>
            <file>
                <path>${project.build.directory}/${project.artifactId}-${project.version}.${project.packaging}</path>
            </file>
        </newVersion>
        <parameter>
            <!-- see documentation -->
        </parameter>
    </configuration>
    <executions>
        <execution>
            <phase>verify</phase>
            <goals>
                <goal>cmp</goal>
            </goals>
        </execution>
    </executions>
</plugin>

A Sonar Qube plugin integrates the results from the japicmp analysis into your code quality report: sonar-japicmp-plugin.

By using the available Ant task, you can also integrate japicmp into your Ant build files:

<taskdef resource="japicmp/ant/antlib.xml" classpathref="https://github.com/siom79/japicmp/blob/master/task.classpath"/>
<japicmp oldjar="${project.build.directory}/guava-18.0.jar"
     newjar="${project.build.directory}/guava-19.0.jar"
     oldclasspathref="https://github.com/siom79/japicmp/blob/master/old.classpath"
     newclasspathref="https://github.com/siom79/japicmp/blob/master/new.classpath"
     onlybinaryincompatiblemodifications="false"
     onlyModifications="true"
     />

melix has developed a gradle plugin for japicmp.

Online-Version

There is an online version of japicmp that lets you compare two artifacts from the maven central repository without installing the tool first. Just click this link and give it a try.

Motivation

Every time you release a new version of a library or a product, you have to tell your clients or customers what has changed in comparison to the last release. Without the appropriate tooling, this task is tedious and error-prone. This tool/library helps you to determine the differences between the java class files that are contained in two given jar archives.

This library does not use the Java Reflection API to compute the differences, as the usage of the Reflection API makes it necessary to include all classes the jar archive under investigation depends on are available on the classpath. To prevent the inclusion of all dependencies, which can be a lot of work for bigger applications, this library makes use of the javassist library to inspect the class files. This way you only have to provide the two jar archives on the command line (and eventually libraries that contain classes/interfaces you have extended/implemented).

This approach also detects changes in instrumented and generated classes. You can even evaluate changes in class file attributes (like synthetic) or annotations. The comparison of annotations makes this approach suitable for annotation-based APIs like JAXB, JPA, JAX-RS, etc.

The goal of this project is to provide a fast and easy to use API comparison for Java. Therefore it does not aim to integrate change tracking of other types of artifacts (configuration files, etc.) as a generic implementation means to make compromises in terms of performance and ease of usage. japicmp for example compares two archives with about 1700 classes each in less than one second and therewith can be easily integrated in each build.

Features

Downloads

You can download the latest version from the release page or directly from the maven central repository.

Buy me a coffee

If you like japicmp and would like to do me a favor for all the work I've done over the years, please consider buying me a coffee here.

Buy Me A Coffee

Development

Reports

Use the maven site plugin (mvn site) to generate the following reports:

Release

This is the release procedure:

Contributions

Pull requests are welcome, but please follow these rules:

Website

The website can be generated by running this github Action on the tag.

It uses the maven-scm-publish-plugin to generate the site report and push it to the gh-pages branch.