Skip to content

Commit a795065

Browse files
committed
Polish "Lazily query attributes when copying from base configuration"
See gh-37343
1 parent 7edc9eb commit a795065

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootAotPlugin.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,8 @@ private void configureAotTask(Project project, SourceSet sourceSet, AbstractAot
151151
task.getArtifactId().set(project.provider(() -> project.getName()));
152152
}
153153

154-
@SuppressWarnings("unchecked")
154+
@SuppressWarnings({ "unchecked", "rawtypes" })
155155
private Configuration createAotProcessingClasspath(Project project, String taskName, SourceSet inputSourceSet) {
156-
ProviderFactory providers = project.getProviders();
157156
Configuration base = project.getConfigurations()
158157
.getByName(inputSourceSet.getRuntimeClasspathConfigurationName());
159158
Configuration aotClasspath = project.getConfigurations().create(taskName + "Classpath", (classpath) -> {
@@ -162,10 +161,11 @@ private Configuration createAotProcessingClasspath(Project project, String taskN
162161
classpath.setDescription("Classpath of the " + taskName + " task.");
163162
removeDevelopmentOnly(base.getExtendsFrom()).forEach(classpath::extendsFrom);
164163
classpath.attributes((attributes) -> {
164+
ProviderFactory providers = project.getProviders();
165165
AttributeContainer baseAttributes = base.getAttributes();
166-
for (Attribute<?> attribute : baseAttributes.keySet()) {
167-
Attribute<Object> attr = (Attribute<Object>) attribute;
168-
attributes.attributeProvider(attr, providers.provider(() -> baseAttributes.getAttribute(attr)));
166+
for (Attribute attribute : baseAttributes.keySet()) {
167+
attributes.attributeProvider(attribute,
168+
providers.provider(() -> baseAttributes.getAttribute(attribute)));
169169
}
170170
});
171171
});

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/SpringBootAotPluginIntegrationTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323

2424
import org.gradle.testkit.runner.TaskOutcome;
2525
import org.junit.jupiter.api.TestTemplate;
26+
import org.junit.jupiter.api.condition.EnabledOnJre;
27+
import org.junit.jupiter.api.condition.JRE;
2628

2729
import org.springframework.boot.gradle.junit.GradleCompatibility;
2830
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;
2931

3032
import static org.assertj.core.api.Assertions.assertThat;
33+
import static org.assertj.core.api.Assertions.assertThatNoException;
3134

3235
/**
3336
* Integration tests for {@link SpringBootAotPlugin}.
@@ -121,6 +124,13 @@ void processTestAotIsSkippedWhenProjectHasNoTestSource() {
121124
.isEqualTo(TaskOutcome.NO_SOURCE);
122125
}
123126

127+
// gh-37343
128+
@TestTemplate
129+
@EnabledOnJre(JRE.JAVA_17)
130+
void applyingAotPluginDoesNotPreventConfigurationOfJavaToolchainLanguageVersion() {
131+
assertThatNoException().isThrownBy(() -> this.gradleBuild.build("help").getOutput());
132+
}
133+
124134
private void writeMainClass(String packageName, String className) throws IOException {
125135
File java = new File(this.gradleBuild.getProjectDir(),
126136
"src/main/java/" + packageName.replace(".", "/") + "/" + className + ".java");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
plugins {
2+
id 'org.springframework.boot'
3+
id 'org.springframework.boot.aot'
4+
id 'java'
5+
}
6+
7+
java {
8+
toolchain {
9+
languageVersion.set(JavaLanguageVersion.of(17))
10+
}
11+
}

0 commit comments

Comments
 (0)