Exclude developmentOnly dependences from AOT processing classpaths
Fixes gh-35433
This commit is contained in:
parent
25375679e6
commit
c39a37cd23
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
package org.springframework.boot.gradle.plugin;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
|
|
@ -155,7 +158,7 @@ public class SpringBootAotPlugin implements Plugin<Project> {
|
|||
classpath.setCanBeConsumed(false);
|
||||
classpath.setCanBeResolved(true);
|
||||
classpath.setDescription("Classpath of the " + taskName + " task.");
|
||||
base.getExtendsFrom().forEach(classpath::extendsFrom);
|
||||
removeDevelopmentOnly(base.getExtendsFrom()).forEach(classpath::extendsFrom);
|
||||
classpath.attributes((attributes) -> {
|
||||
AttributeContainer baseAttributes = base.getAttributes();
|
||||
for (Attribute<?> attribute : baseAttributes.keySet()) {
|
||||
|
|
@ -166,6 +169,14 @@ public class SpringBootAotPlugin implements Plugin<Project> {
|
|||
return aotClasspath;
|
||||
}
|
||||
|
||||
private Stream<Configuration> removeDevelopmentOnly(Set<Configuration> configurations) {
|
||||
return configurations.stream().filter(this::isNotDevelopmentOnly);
|
||||
}
|
||||
|
||||
private boolean isNotDevelopmentOnly(Configuration configuration) {
|
||||
return !SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME.equals(configuration.getName());
|
||||
}
|
||||
|
||||
private void configureDependsOn(Project project, SourceSet aotSourceSet,
|
||||
TaskProvider<? extends AbstractAot> processAot) {
|
||||
project.getTasks()
|
||||
|
|
|
|||
|
|
@ -95,6 +95,18 @@ class SpringBootAotPluginIntegrationTests {
|
|||
assertThat(output).contains("org.jboss.logging" + File.separatorChar + "jboss-logging");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void processAotDoesNotHaveDevelopmentOnlyDependenciesOnItsClasspath() {
|
||||
String output = this.gradleBuild.build("processAotClasspath").getOutput();
|
||||
assertThat(output).doesNotContain("commons-lang");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void processTestAotDoesNotHaveDevelopmentOnlyDependenciesOnItsClasspath() {
|
||||
String output = this.gradleBuild.build("processTestAotClasspath", "--stacktrace").getOutput();
|
||||
assertThat(output).doesNotContain("commons-lang");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void processAotRunsWhenProjectHasMainSource() throws IOException {
|
||||
writeMainClass("org.springframework.boot", "SpringApplicationAotProcessor");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
plugins {
|
||||
id 'org.springframework.boot' version '{version}'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot.aot'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
developmentOnly("org.apache.commons:commons-lang3:3.12.0")
|
||||
}
|
||||
|
||||
task('processAotClasspath') {
|
||||
doFirst {
|
||||
tasks.processAot.classpath.each { println it }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
plugins {
|
||||
id 'org.springframework.boot' version '{version}'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
apply plugin: 'org.springframework.boot.aot'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'file:repository' }
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
resolutionStrategy {
|
||||
eachDependency {
|
||||
if (it.requested.group == 'org.springframework.boot') {
|
||||
it.useVersion project.bootVersion
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
developmentOnly("org.apache.commons:commons-lang3:3.12.0")
|
||||
}
|
||||
|
||||
task('processTestAotClasspath') {
|
||||
doFirst {
|
||||
tasks.processTestAot.classpath.each { println it }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue