[Gradle 1.8-rc-1] Alternative to LatestVersionSemanticComparator

The versions plugin provides a task to discover dependency updates. It uses an internal api to sort the resolved dependencies into groupings (upgrades, at latest, beyond latest - e.g. snapshots). The comparator was deleted in 1.8, understandably since its not a public class.

What is the best alternative for making this plugin 1.8 compatible? Is it to embed a copy of the comparator, which relies upon ivy classes? Is there a Gradle api that provides equivalent functionality? See the usage for details.

Resolved by using ‘ResolverStrategy’ and reflective instantiation to compatible with multiple gradle releases.

This change may have uncovered a bug in Gradle’s dependency resolution listing. It results in a NPE in certain scenarios by providing incorrect library listings. The assumption is that declared = (resolved + unresolved) dependencies. Instead the resolved dependencies includes extra dependencies from adjacent projects. This resulted in a NPE as the mapping for a key was not found (‘comparator.compare(version, currentVersions[key]) > 0’).

For more details see the plugin’s issue.

Thanks for the feedback. Do you have a self-contained reproducible example for this (outside your plugin)?

I can probably get an example, using the plugin, to fail for debugging. If I can get that far then since the plugin is simple gradle api calls, we can decide whether to pull out those calls or debug with the plugin. I would write this as a spock integration test, but a previous Gradle version broke the test’s ability to resolve dependencies from maven central.

Here is a minimal example. It clearly demonstrates that v1.7 and v1.8-rc-1 differ.

Thanks for the example. According to ‘git-bisect’, commit c19bb005a1b introduces the problem. I’ve created GRADLE-2889 for this.

By the way, it appears that the configuration’s files are nevertheless correct, and if the code is slightly changed so that it doesn’t use a detached configuration, the resolved dependencies are printed correctly.

Thanks a lot Peter and Ben for the investigation. The sample project was very useful. I’ve pushed the fix to the release branch already.