Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More fixes for binary compatibility checks #586

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void apply(Project project) {
project.getPluginManager().withPlugin("java-library", alsoUnused -> {
TaskProvider<FindBaselineTask> baselineTask = registerFindBaselineTask(project, binaryCompatibility, tasks, providers);
Provider<String> baseline = createBaselineProvider(binaryCompatibility, providers, baselineTask);
String groupAndArtifact = project.getGroup() + ":" + moduleNameOf(project.getName());
String groupAndArtifact = findGroupOf(project) + ":" + moduleNameOf(project.getName());
Configuration oldClasspath = rootProjectConfigurations.detachedConfiguration();
Configuration oldJar = rootProjectConfigurations.detachedConfiguration();
oldClasspath.getDependencies().addLater(baseline.map(version -> project.getDependencies().create(groupAndArtifact + ":" + version)));
Expand Down Expand Up @@ -111,7 +111,7 @@ public void apply(Project project) {
TaskProvider<FindBaselineTask> baselineTask = registerFindBaselineTask(project, binaryCompatibility, tasks, providers);
Provider<String> baseline = createBaselineProvider(binaryCompatibility, providers, baselineTask);
Configuration baselineConfig = rootProjectConfigurations.detachedConfiguration();
baselineConfig.getDependencies().addLater(baseline.map(version -> project.getDependencies().create(project.getGroup() + ":" + moduleNameOf(project.getName()) + ":" + version + "@toml")));
baselineConfig.getDependencies().addLater(baseline.map(version -> project.getDependencies().create(findGroupOf(project) + ":" + moduleNameOf(project.getName()) + ":" + version + "@toml")));
TaskProvider<VersionCatalogCompatibilityCheck> compatibilityCheckTaskProvider = tasks.register("checkVersionCatalogCompatibility", VersionCatalogCompatibilityCheck.class, task -> {
task.onlyIf(t -> binaryCompatibility.getEnabled().getOrElse(true));
if (binaryCompatibility.getBaselineVersion().isPresent()) {
Expand All @@ -131,6 +131,11 @@ public void apply(Project project) {
});
}

private static String findGroupOf(Project project) {
ProviderFactory providers = project.getProviders();
return providers.gradleProperty("projectGroupId").orElse(providers.gradleProperty("projectGroup")).getOrElse(project.getGroup().toString());
}

private Provider<String> createBaselineProvider(BinaryCompatibibilityExtension binaryCompatibility, ProviderFactory providers, TaskProvider<FindBaselineTask> baselineTask) {
return binaryCompatibility.getBaselineVersion().orElse(
providers.fileContents(baselineTask.flatMap(FindBaselineTask::getPreviousVersion))
Expand All @@ -141,7 +146,10 @@ private Provider<String> createBaselineProvider(BinaryCompatibibilityExtension b
private TaskProvider<FindBaselineTask> registerFindBaselineTask(Project project, BinaryCompatibibilityExtension binaryCompatibility, TaskContainer tasks, ProviderFactory providers) {
Provider<ExternalURLService> downloader = ExternalURLService.registerOn(project);
return tasks.register("findBaseline", FindBaselineTask.class, task -> {
task.onlyIf(t -> binaryCompatibility.getEnabled().getOrElse(true));
task.onlyIf(t ->
binaryCompatibility.getEnabled().getOrElse(true) &&
!binaryCompatibility.getBaselineVersion().isPresent()
);
task.usesService(downloader);
task.getDownloader().set(downloader);
task.getBaseRepository().convention("https://repo1.maven.org/maven2");
Expand Down