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

predeclareDepsFromBuildscript - Mutating configuration container for buildscript of root project has been deprecated. #2394

Open
simon-spinner opened this issue Jan 10, 2025 · 6 comments
Labels

Comments

@simon-spinner
Copy link

Summary:
Gradle shows a deprecation warning when Spotless is used in a multi-module build with:

spotless {
    predeclareDepsFromBuildscript()
}

Warning:
Mutating configuration container for buildscript of root project 'xy' using create(String) has been deprecated.
This will fail with an error in Gradle 9.0.

Gradle: 8.12
Spotless: 7.0.1

@nedtwigg nedtwigg added the bug label Jan 10, 2025
@nedtwigg nedtwigg changed the title Mutating configuration container for buildscript of root project using create(String) has been deprecated. predeclareDepsFromBuildscript - Mutating configuration container for buildscript of root project has been deprecated. Jan 10, 2025
@nedtwigg
Copy link
Member

Does spotlessPredeclare trigger this same behavior? Seems that Gradle has been moving away from the buildscript model in general, possible that we'll have to lose it.

@simon-spinner
Copy link
Author

If I leave out predeclareDepsFromBuildscript so that the dependencies are pulled from the root project, the deprecation warning does not show up. We are using the legacy behavior as a workaround, because the maven repository definition in the projects apply content filters. As the name of the configuration that spotless uses to download dependencies is dynamic, I cannot whitelist it.

@nedtwigg
Copy link
Member

Roger. So we either need to:

  • figure out a way around the deprecation
  • make the configuration names friendlier

Here is the relevant code, PRs welcome

static Provisioner forProject(Project project) {
return forConfigurationContainer(project, project.getConfigurations(), project.getDependencies());
}
static Provisioner forRootProjectBuildscript(Project project) {
Project rootProject = project.getRootProject();
ScriptHandler buildscript = rootProject.getBuildscript();
return forConfigurationContainer(rootProject, buildscript.getConfigurations(), buildscript.getDependencies());
}
private static Provisioner forConfigurationContainer(Project project, ConfigurationContainer configurations, DependencyHandler dependencies) {
return (withTransitives, mavenCoords) -> {
try {
Configuration config = configurations.create("spotless"
+ new Request(withTransitives, mavenCoords).hashCode());
mavenCoords.stream()
.map(dependencies::create)
.forEach(config.getDependencies()::add);
config.setDescription(mavenCoords.toString());
config.setTransitive(withTransitives);
config.setCanBeConsumed(false);
config.setVisible(false);
config.attributes(attr -> {
attr.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.LIBRARY));
attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL));
// TODO: This is a copy-paste from org.gradle.api.attributes.java.TargetJvmEnvironment which is added in Gradle 7.0, remove this once we drop support for Gradle 6.x.
// Add this attribute for resolving Guava dependency, see https://github.com/google/guava/issues/6801.
attr.attribute(Attribute.of("org.gradle.jvm.environment", String.class), "standard-jvm");
});
return config.resolve();
} catch (Exception e) {
String projName = project.getPath().substring(1).replace(':', '/');
if (!projName.isEmpty()) {
projName = projName + "/";
}
throw new GradleException(String.format(
"You need to add a repository containing the '%s' artifact in '%sbuild.gradle'.%n" +
"E.g.: 'repositories { mavenCentral() }'",
mavenCoords, projName), e);
}
};
}

@simon-spinner
Copy link
Author

Why does it include a hashcode in the configuration name? Can there be multiple such configurations in the same project?

@nedtwigg
Copy link
Member

There can be multiple spotless configurations, yeah. But there is only one for each step. Easiest would be to change the name to be based on the maven coordinate of the first jar, could be with or without the version string.

  • spotless-com.google.googlejavaformat:google-java-format:1.25.2
  • spotless-com.google.googlejavaformat:google-java-format

Could also remove the group, which would make it just

  • spotless-google-java-format

Which configuration naming convention would work best for you?

@simon-spinner
Copy link
Author

If we can leave out the version number from the name, that would be great. I don't have an opinion whether the group id should be included or not. Works both for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants