Skip to content

Commit

Permalink
Upgrade to Gradle 8.4-rc-1 (#838)
Browse files Browse the repository at this point in the history
* Upgrade to Gradle 8.4-rc-1

This is to find potential problems before final version.

Fixes #837

* Use attribute providers for copying attributes
  • Loading branch information
melix authored Oct 11, 2023
1 parent 7269dd8 commit 75de851
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ private void registerJavaExecOptimizedRun(Project project,
conf.setCanBeConsumed(false);
conf.setCanBeConsumed(true);
// Use the same attributes as runtimeClasspath for resolution
AttributeUtils.copyAttributes(runtimeClasspath, conf);
AttributeUtils.copyAttributes(project.getProviders(), runtimeClasspath, conf);
});

tasks.register("optimizedRun", JavaExec.class, task -> {
Expand Down Expand Up @@ -371,8 +371,9 @@ private TaskProvider<MicronautAotOptimizerTask> registerPrepareOptimizationTask(
private Configurations prepareConfigurations(Project project, AOTExtension aotExtension) {
ConfigurationContainer configurations = project.getConfigurations();
// Internal configurations
var providers = project.getProviders();
Configuration aotOptimizerRuntimeClasspath = configurations.create("aotOptimizerRuntimeClasspath", c -> {
configureAsRuntimeClasspath(configurations, c);
configureAsRuntimeClasspath(providers, configurations, c);
c.getDependencies().addLater(aotExtension.getVersion().map(v -> project.getDependencies().create("io.micronaut.aot:micronaut-aot-api:" + v)));
c.getDependencies().addLater(aotExtension.getVersion().map(v -> project.getDependencies().create("io.micronaut.aot:micronaut-aot-std-optimizers:" + v)));
c.getDependencies().addLater(aotExtension.getVersion().map(v -> project.getDependencies().create("io.micronaut.aot:micronaut-aot-cli:" + v)));
Expand All @@ -388,7 +389,7 @@ private Configurations prepareConfigurations(Project project, AOTExtension aotEx
c.setCanBeConsumed(false);
});
Configuration aotApplicationClasspath = configurations.create(AOT_APPLICATION_CLASSPATH, c -> {
configureAsRuntimeClasspath(configurations, c);
configureAsRuntimeClasspath(providers, configurations, c);
Configuration runtimeClasspath = configurations.findByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
runtimeClasspath.getExtendsFrom().forEach(c::extendsFrom);
c.extendsFrom(aotApplication);
Expand All @@ -401,12 +402,12 @@ private Configurations prepareConfigurations(Project project, AOTExtension aotEx
);
}

private void configureAsRuntimeClasspath(ConfigurationContainer configurations, Configuration configuration) {
private void configureAsRuntimeClasspath(ProviderFactory providers, ConfigurationContainer configurations, Configuration configuration) {
configuration.setCanBeResolved(true);
configuration.setCanBeConsumed(false);

Configuration runtimeClasspath = configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
AttributeUtils.copyAttributes(runtimeClasspath, configuration);
AttributeUtils.copyAttributes(providers, runtimeClasspath, configuration);
}

private static class JarExclusionSpec implements Action<FileCopyDetails> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ publishing {
publications.register(pubName, MavenPublication) {
project.afterEvaluate {
def component = pub.component
// Dirty trick to restore Gradle <8.3 behavior
if (component.isPresent()) {
component = component.get()
} else {
component = null
}
from(component)
alias = true
groupId = pub.groupId
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.attributes.Attribute;
import org.gradle.api.attributes.AttributeContainer;
import org.gradle.api.provider.ProviderFactory;

import java.util.Set;

Expand All @@ -34,13 +35,13 @@ private AttributeUtils() {
* @param from the source configuration
* @param to the target configuration
*/
public static void copyAttributes(Configuration from, Configuration to) {
public static void copyAttributes(ProviderFactory providers, Configuration from, Configuration to) {
from.attributes(attrs -> {
AttributeContainer runtimeClasspathAttributes = to.getAttributes();
Set<Attribute<?>> keySet = runtimeClasspathAttributes.keySet();
for (Attribute<?> attribute : keySet) {
//noinspection unchecked,DataFlowIssue
attrs.attribute((Attribute<Object>) attribute, runtimeClasspathAttributes.getAttribute(attribute));
attrs.attributeProvider((Attribute<Object>) attribute, providers.provider(() -> runtimeClasspathAttributes.getAttribute(attribute)));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void configureJavaExecTasks(Project project, Configuration developmentOn
Configuration runtimeClasspath = configurations.getByName("runtimeClasspath");
conf.extendsFrom(runtimeClasspath);
conf.extendsFrom(developmentOnlyConfiguration);
AttributeUtils.copyAttributes(runtimeClasspath, conf);
AttributeUtils.copyAttributes(project.getProviders(), runtimeClasspath, conf);
});
tasks.withType(JavaExec.class).configureEach(javaExec -> {
var sourceSets = PluginsHelper.findSourceSets(project);
Expand Down

0 comments on commit 75de851

Please sign in to comment.