Skip to content
This repository was archived by the owner on Sep 25, 2025. It is now read-only.

Add API Compatibility Task to Java Libraries#25

Merged
jimmyjames merged 4 commits intomasterfrom
add-japiplugin
Feb 22, 2021
Merged

Add API Compatibility Task to Java Libraries#25
jimmyjames merged 4 commits intomasterfrom
add-japiplugin

Conversation

@jimmyjames
Copy link
Copy Markdown
Contributor

@jimmyjames jimmyjames commented Feb 18, 2021

Description

Currently, we rely on manual inspection of changes to ensure no breaking changes are introduced. Instead, we can leverage an API compatibility-checker, JApiCmp through the JApicmp Gradle Plugin.

This change adds a task, apiDiff, to Java projects that specify a baselineCompareVersion property in the oss config:

oss {
    // ...
    baselineCompareVersion "3.13.0"
}

Details:

  • The task will not be added if the baselineCompareVersion configuration property is not added
  • The task will not be added to Android projects with this change. As we utilize it for Java projects first, we can extract the task to handle Android as well if it proves useful.

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not master

@jimmyjames jimmyjames added CH: Added PR is adding feature or functionality review:medium Medium review labels Feb 18, 2021
@jimmyjames jimmyjames requested a review from a team as a code owner February 18, 2021 21:38
}

private void japiCmp(Project project) {
project.afterEvaluate {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to happen after evaluation so plugin config settings are available.

project.afterEvaluate {
def lib = project.extensions.oss
def baselineVersion = lib.baselineVersion
if (baselineVersion) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's invert this condition and return sooner

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new commit to invert and return earlier pushed.

apply plugin: 'me.champeau.gradle.japicmp'
task('apiDiff', type: JapicmpTask, dependsOn: 'jar') {
oldClasspath = files(getBaselineJar(project, baselineVersion))
newClasspath = files("$buildDir/libs/${project.name}-${project.version}.jar")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could use archiveFile here instead of hardcoding the name. Archive File is a property from the Jar task

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 new commit to use the archiveFile pushed.

it.name == "${project.name}-${baselineVersion}.jar"
}
} finally {
project.group = group
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if the baseline jar is found, the group gets updated before adding the dependency; but after that, it gets reset to the original value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct. Similar to what okhttp does, and seen the same pattern in other repos.

String organization
String repository
String description
String baselineVersion
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prop name has a meaning in the context of the japicmp plugin. How about here? Maybe we can come up with a better name that explains that diff check (can't think of any right now)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about baselineCompareVersion? It's a little long, but maybe is clearer?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree it's clearer and I don't mind it being long as long if it's descriptive. Let's change it 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New commit to rename to baselineCompareVersion pushed. Will also update the PR description with the new name.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

CH: Added PR is adding feature or functionality review:medium Medium review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants