Commit 514aede9 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge branch '2.4.x'

Closes gh-25168
parents d4365214 45e6c12c
...@@ -22,6 +22,7 @@ import java.util.concurrent.Callable; ...@@ -22,6 +22,7 @@ import java.util.concurrent.Callable;
import java.util.function.Function; import java.util.function.Function;
import org.gradle.api.Action; import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ResolvableDependencies; import org.gradle.api.artifacts.ResolvableDependencies;
import org.gradle.api.file.CopySpec; import org.gradle.api.file.CopySpec;
import org.gradle.api.file.FileCollection; import org.gradle.api.file.FileCollection;
...@@ -72,15 +73,16 @@ public class BootJar extends Jar implements BootArchive { ...@@ -72,15 +73,16 @@ public class BootJar extends Jar implements BootArchive {
*/ */
public BootJar() { public BootJar() {
this.support = new BootArchiveSupport(LAUNCHER, new LibrarySpec(), new ZipCompressionResolver()); this.support = new BootArchiveSupport(LAUNCHER, new LibrarySpec(), new ZipCompressionResolver());
this.bootInfSpec = getProject().copySpec().into("BOOT-INF"); Project project = getProject();
this.mainClass = getProject().getObjects().property(String.class); this.bootInfSpec = project.copySpec().into("BOOT-INF");
this.mainClass = project.getObjects().property(String.class);
configureBootInfSpec(this.bootInfSpec); configureBootInfSpec(this.bootInfSpec);
getMainSpec().with(this.bootInfSpec); getMainSpec().with(this.bootInfSpec);
getProject().getConfigurations().all((configuration) -> { project.getConfigurations().all((configuration) -> {
ResolvableDependencies incoming = configuration.getIncoming(); ResolvableDependencies incoming = configuration.getIncoming();
incoming.afterResolve((resolvableDependencies) -> { incoming.afterResolve((resolvableDependencies) -> {
if (resolvableDependencies == incoming) { if (resolvableDependencies == incoming) {
this.resolvedDependencies.processConfiguration(configuration); this.resolvedDependencies.processConfiguration(project, configuration);
} }
}); });
}); });
......
...@@ -70,15 +70,16 @@ public class BootWar extends War implements BootArchive { ...@@ -70,15 +70,16 @@ public class BootWar extends War implements BootArchive {
*/ */
public BootWar() { public BootWar() {
this.support = new BootArchiveSupport(LAUNCHER, new LibrarySpec(), new ZipCompressionResolver()); this.support = new BootArchiveSupport(LAUNCHER, new LibrarySpec(), new ZipCompressionResolver());
this.mainClass = getProject().getObjects().property(String.class); Project project = getProject();
this.mainClass = project.getObjects().property(String.class);
getWebInf().into("lib-provided", fromCallTo(this::getProvidedLibFiles)); getWebInf().into("lib-provided", fromCallTo(this::getProvidedLibFiles));
this.support.moveModuleInfoToRoot(getRootSpec()); this.support.moveModuleInfoToRoot(getRootSpec());
getRootSpec().eachFile(this.support::excludeNonZipLibraryFiles); getRootSpec().eachFile(this.support::excludeNonZipLibraryFiles);
getProject().getConfigurations().all((configuration) -> { project.getConfigurations().all((configuration) -> {
ResolvableDependencies incoming = configuration.getIncoming(); ResolvableDependencies incoming = configuration.getIncoming();
incoming.afterResolve((resolvableDependencies) -> { incoming.afterResolve((resolvableDependencies) -> {
if (resolvableDependencies == incoming) { if (resolvableDependencies == incoming) {
this.resolvedDependencies.processConfiguration(configuration); this.resolvedDependencies.processConfiguration(project, configuration);
} }
}); });
}); });
......
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -22,9 +22,9 @@ import java.util.Map; ...@@ -22,9 +22,9 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ModuleVersionIdentifier; import org.gradle.api.artifacts.ModuleVersionIdentifier;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.artifacts.ResolvedArtifact; import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.artifacts.ResolvedConfiguration; import org.gradle.api.artifacts.ResolvedConfiguration;
...@@ -44,13 +44,15 @@ class ResolvedDependencies { ...@@ -44,13 +44,15 @@ class ResolvedDependencies {
private final Map<Configuration, ResolvedConfigurationDependencies> configurationDependencies = new LinkedHashMap<>(); private final Map<Configuration, ResolvedConfigurationDependencies> configurationDependencies = new LinkedHashMap<>();
void processConfiguration(Configuration configuration) { private String projectId(Project project) {
Set<String> projectDependencyIds = configuration.getAllDependencies().withType(ProjectDependency.class).stream() return project.getGroup() + ":" + project.getName() + ":" + project.getVersion();
.map((projectDependency) -> projectDependency.getGroup() + ":" + projectDependency.getName() + ":" }
+ projectDependency.getVersion())
void processConfiguration(Project project, Configuration configuration) {
Set<String> localProjectIds = project.getRootProject().getAllprojects().stream().map(this::projectId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
this.configurationDependencies.put(configuration, this.configurationDependencies.put(configuration,
new ResolvedConfigurationDependencies(projectDependencyIds, configuration.getResolvedConfiguration())); new ResolvedConfigurationDependencies(localProjectIds, configuration.getResolvedConfiguration()));
} }
DependencyDescriptor find(File file) { DependencyDescriptor find(File file) {
......
...@@ -326,6 +326,7 @@ abstract class AbstractBootArchiveIntegrationTests { ...@@ -326,6 +326,7 @@ abstract class AbstractBootArchiveIntegrationTests {
assertThat(jarFile.getEntry(layerToolsJar)).isNotNull(); assertThat(jarFile.getEntry(layerToolsJar)).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "alpha-1.2.3.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "alpha-1.2.3.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "bravo-1.2.3.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "bravo-1.2.3.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "charlie-1.2.3.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "commons-lang3-3.9.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "commons-lang3-3.9.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "spring-core-5.2.5.RELEASE.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "spring-core-5.2.5.RELEASE.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "spring-jcl-5.2.5.RELEASE.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "spring-jcl-5.2.5.RELEASE.jar")).isNotNull();
...@@ -347,8 +348,9 @@ abstract class AbstractBootArchiveIntegrationTests { ...@@ -347,8 +348,9 @@ abstract class AbstractBootArchiveIntegrationTests {
assertThat(indexedLayers.get("dependencies")).containsExactlyElementsOf(expectedDependencies); assertThat(indexedLayers.get("dependencies")).containsExactlyElementsOf(expectedDependencies);
assertThat(indexedLayers.get("spring-boot-loader")).containsExactly("org/"); assertThat(indexedLayers.get("spring-boot-loader")).containsExactly("org/");
assertThat(indexedLayers.get("snapshot-dependencies")).containsExactlyElementsOf(expectedSnapshotDependencies); assertThat(indexedLayers.get("snapshot-dependencies")).containsExactlyElementsOf(expectedSnapshotDependencies);
assertThat(indexedLayers.get("application")).containsExactly(getExpectedApplicationLayerContents( assertThat(indexedLayers.get("application"))
this.classesPath, this.libPath + "alpha-1.2.3.jar", this.libPath + "bravo-1.2.3.jar")); .containsExactly(getExpectedApplicationLayerContents(this.classesPath, this.libPath + "alpha-1.2.3.jar",
this.libPath + "bravo-1.2.3.jar", this.libPath + "charlie-1.2.3.jar"));
BuildResult listLayers = this.gradleBuild.build("listLayers"); BuildResult listLayers = this.gradleBuild.build("listLayers");
assertThat(listLayers.task(":listLayers").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); assertThat(listLayers.task(":listLayers").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
String listLayersOutput = listLayers.getOutput(); String listLayersOutput = listLayers.getOutput();
...@@ -417,6 +419,7 @@ abstract class AbstractBootArchiveIntegrationTests { ...@@ -417,6 +419,7 @@ abstract class AbstractBootArchiveIntegrationTests {
assertThat(jarFile.getEntry(layerToolsJar)).isNotNull(); assertThat(jarFile.getEntry(layerToolsJar)).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "alpha-1.2.3.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "alpha-1.2.3.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "bravo-1.2.3.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "bravo-1.2.3.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "charlie-1.2.3.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "commons-lang3-3.9.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "commons-lang3-3.9.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "spring-core-5.2.5.RELEASE.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "spring-core-5.2.5.RELEASE.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "spring-jcl-5.2.5.RELEASE.jar")).isNotNull(); assertThat(jarFile.getEntry(this.libPath + "spring-jcl-5.2.5.RELEASE.jar")).isNotNull();
...@@ -432,6 +435,7 @@ abstract class AbstractBootArchiveIntegrationTests { ...@@ -432,6 +435,7 @@ abstract class AbstractBootArchiveIntegrationTests {
Set<String> expectedSubprojectDependencies = new TreeSet<>(); Set<String> expectedSubprojectDependencies = new TreeSet<>();
expectedSubprojectDependencies.add(this.libPath + "alpha-1.2.3.jar"); expectedSubprojectDependencies.add(this.libPath + "alpha-1.2.3.jar");
expectedSubprojectDependencies.add(this.libPath + "bravo-1.2.3.jar"); expectedSubprojectDependencies.add(this.libPath + "bravo-1.2.3.jar");
expectedSubprojectDependencies.add(this.libPath + "charlie-1.2.3.jar");
Set<String> expectedDependencies = new TreeSet<>(); Set<String> expectedDependencies = new TreeSet<>();
expectedDependencies.add(this.libPath + "spring-core-5.2.5.RELEASE.jar"); expectedDependencies.add(this.libPath + "spring-core-5.2.5.RELEASE.jar");
expectedDependencies.add(this.libPath + "spring-jcl-5.2.5.RELEASE.jar"); expectedDependencies.add(this.libPath + "spring-jcl-5.2.5.RELEASE.jar");
...@@ -492,7 +496,7 @@ abstract class AbstractBootArchiveIntegrationTests { ...@@ -492,7 +496,7 @@ abstract class AbstractBootArchiveIntegrationTests {
private void writeSettingsGradle() { private void writeSettingsGradle() {
try (PrintWriter writer = new PrintWriter( try (PrintWriter writer = new PrintWriter(
new FileWriter(new File(this.gradleBuild.getProjectDir(), "settings.gradle")))) { new FileWriter(new File(this.gradleBuild.getProjectDir(), "settings.gradle")))) {
writer.println("include 'alpha', 'bravo'"); writer.println("include 'alpha', 'bravo', 'charlie'");
} }
catch (IOException ex) { catch (IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
......
...@@ -116,7 +116,7 @@ class BootJarTests extends AbstractBootArchiveTests<BootJar> { ...@@ -116,7 +116,7 @@ class BootJarTests extends AbstractBootArchiveTests<BootJar> {
@Override @Override
void populateResolvedDependencies(Configuration configuration) { void populateResolvedDependencies(Configuration configuration) {
getTask().getResolvedDependencies().processConfiguration(configuration); getTask().getResolvedDependencies().processConfiguration(getTask().getProject(), configuration);
} }
@Override @Override
......
...@@ -116,7 +116,7 @@ class BootWarTests extends AbstractBootArchiveTests<BootWar> { ...@@ -116,7 +116,7 @@ class BootWarTests extends AbstractBootArchiveTests<BootWar> {
@Override @Override
void populateResolvedDependencies(Configuration configuration) { void populateResolvedDependencies(Configuration configuration) {
getTask().getResolvedDependencies().processConfiguration(configuration); getTask().getResolvedDependencies().processConfiguration(getTask().getProject(), configuration);
} }
@Override @Override
......
...@@ -7,6 +7,11 @@ subprojects { ...@@ -7,6 +7,11 @@ subprojects {
apply plugin: 'java' apply plugin: 'java'
group = 'org.example.projects' group = 'org.example.projects'
version = '1.2.3' version = '1.2.3'
if (it.name == 'bravo') {
dependencies {
implementation(project(':charlie'))
}
}
} }
bootJar { bootJar {
......
...@@ -7,6 +7,11 @@ subprojects { ...@@ -7,6 +7,11 @@ subprojects {
apply plugin: 'java' apply plugin: 'java'
group = 'org.example.projects' group = 'org.example.projects'
version = '1.2.3' version = '1.2.3'
if (it.name == 'bravo') {
dependencies {
implementation(project(':charlie'))
}
}
} }
bootJar { bootJar {
......
...@@ -8,6 +8,11 @@ subprojects { ...@@ -8,6 +8,11 @@ subprojects {
apply plugin: 'java' apply plugin: 'java'
group = 'org.example.projects' group = 'org.example.projects'
version = '1.2.3' version = '1.2.3'
if (it.name == 'bravo') {
dependencies {
implementation(project(':charlie'))
}
}
} }
bootWar { bootWar {
......
...@@ -8,6 +8,11 @@ subprojects { ...@@ -8,6 +8,11 @@ subprojects {
apply plugin: 'java' apply plugin: 'java'
group = 'org.example.projects' group = 'org.example.projects'
version = '1.2.3' version = '1.2.3'
if (it.name == 'bravo') {
dependencies {
implementation(project(':charlie'))
}
}
} }
bootWar { bootWar {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment