diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/pom.xml index 8c68c4bbf3fc..e914bb9a6ea3 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/pom.xml +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/pom.xml @@ -16,7 +16,6 @@ ./gradlew build false - 1.2.20 diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/configure-bom-with-plugins.gradle.kts b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/configure-bom-with-plugins.gradle.kts index ea2b36bbed9f..3dfcde8bb2dd 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/configure-bom-with-plugins.gradle.kts +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/configure-bom-with-plugins.gradle.kts @@ -1,3 +1,5 @@ +import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension + // tag::configure-bom[] plugins { java @@ -12,16 +14,18 @@ dependencyManagement { } // end::configure-bom[] -dependencyManagement { +the().apply { resolutionStrategy { eachDependency { if (requested.group == "org.springframework.boot") { - useVersion("{version}") + useVersion("TEST-SNAPSHOT") } } } } repositories { - mavenLocal() + maven { + url = uri("file:repository") + } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/configure-bom.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/configure-bom.gradle index a6faa67f75f5..c2de91e1e874 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/configure-bom.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/configure-bom.gradle @@ -17,12 +17,12 @@ dependencyManagement { resolutionStrategy { eachDependency { if (it.requested.group == 'org.springframework.boot') { - it.useVersion '{version}' + it.useVersion 'TEST-SNAPSHOT' } } } } repositories { - mavenLocal() + maven { url 'file:repository' } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/configure-bom.gradle.kts b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/configure-bom.gradle.kts index 4f0d989d6ee3..cd20e55cc070 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/configure-bom.gradle.kts +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/configure-bom.gradle.kts @@ -19,12 +19,14 @@ the().apply { resolutionStrategy { eachDependency { if (requested.group == "org.springframework.boot") { - useVersion("{version}") + useVersion("TEST-SNAPSHOT") } } } } repositories { - mavenLocal() + maven { + url = uri("file:repository") + } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/custom-version.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/custom-version.gradle index ae022ba67b94..211f37a40405 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/custom-version.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/custom-version.gradle @@ -8,7 +8,7 @@ dependencyManagement { resolutionStrategy { eachDependency { if (it.requested.group == 'org.springframework.boot') { - it.useVersion '{version}' + it.useVersion 'TEST-SNAPSHOT' } } } @@ -19,7 +19,7 @@ ext['slf4j.version'] = '1.7.20' // end::custom-version[] repositories { - mavenLocal() + maven { url 'file:repository' } } task slf4jVersion { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/custom-version.gradle.kts b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/custom-version.gradle.kts index 01e9dcf0b126..c7695d6f696b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/custom-version.gradle.kts +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/managing-dependencies/custom-version.gradle.kts @@ -6,24 +6,26 @@ plugins { apply(plugin = "io.spring.dependency-management") +// tag::custom-version[] +extra["slf4j.version"] = "1.7.20" +// end::custom-version[] + +repositories { + maven { + url = uri("file:repository") + } +} + the().apply { resolutionStrategy { eachDependency { if (requested.group == "org.springframework.boot") { - useVersion("{version}") + useVersion("TEST-SNAPSHOT") } } } } -// tag::custom-version[] -extra["slf4j.version"] = "1.7.20" -// end::custom-version[] - -repositories { - mavenLocal() -} - task("slf4jVersion") { doLast { println(project.the().managedVersions["org.slf4j:slf4j-api"]) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/ManagingDependenciesDocumentationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/ManagingDependenciesDocumentationTests.java index ab93a816076a..d9849cb5dedf 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/ManagingDependenciesDocumentationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/ManagingDependenciesDocumentationTests.java @@ -65,8 +65,8 @@ public void dependencyManagementInIsolationWithPluginsBlock() { Assume.assumeTrue(this.gradleBuild.getDsl() == Dsl.KOTLIN); assertThat(this.gradleBuild.script( "src/main/gradle/managing-dependencies/configure-bom-with-plugins") - .build("dependencyManagement").getOutput()) - .contains("org.springframework.boot:spring-boot-starter "); + .build("dependencyManagement").getOutput()).contains( + "org.springframework.boot:spring-boot-starter TEST-SNAPSHOT"); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests.java index 1fcc43794e36..93b7da47f42c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests.java @@ -43,12 +43,10 @@ public void noKotlinVersionPropertyWithoutKotlinPlugin() { } @Test - public void kotlinVersionMatchesKotlinPluginVersion() { + public void kotlinVersionPropertyIsSet() { String output = this.gradleBuild.build("kotlinVersion", "dependencies", "--configuration", "compileClasspath").getOutput(); - assertThat(output).contains("Kotlin version: 1.2.20"); - assertThat(output) - .containsPattern("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.20"); + assertThat(output).containsPattern("Kotlin version: [0-9]\\.[0-9]\\.[0-9]+"); } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java index ba7a46603158..5244300c71bf 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java @@ -24,33 +24,28 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.jar.JarFile; import java.util.regex.Pattern; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathFactory; - import io.spring.gradle.dependencymanagement.DependencyManagementPlugin; +import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension; import org.apache.commons.compress.archivers.ArchiveEntry; import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.GradleRunner; import org.jetbrains.kotlin.cli.common.PropertiesKt; import org.jetbrains.kotlin.compilerRunner.KotlinCompilerRunner; +import org.jetbrains.kotlin.gradle.model.KotlinProject; import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin; import org.jetbrains.kotlin.gradle.plugin.KotlinPlugin; import org.junit.rules.TemporaryFolder; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; import org.springframework.asm.ClassVisitor; import org.springframework.boot.loader.tools.LaunchScript; import org.springframework.util.FileCopyUtils; +import org.springframework.util.FileSystemUtils; /** * A {@link TestRule} for running a Gradle build using {@link GradleRunner}. @@ -146,6 +141,7 @@ private List pluginClasspath() { new File(pathOfJarContaining(PropertiesKt.class)), new File(pathOfJarContaining(KotlinCompilerRunner.class)), new File(pathOfJarContaining(KotlinPlugin.class)), + new File(pathOfJarContaining(KotlinProject.class)), new File(pathOfJarContaining(KotlinGradleSubplugin.class)), new File(pathOfJarContaining(ArchiveEntry.class))); } @@ -185,6 +181,8 @@ public GradleRunner prepareRunner(String... arguments) throws IOException { getDependencyManagementPluginVersion()); FileCopyUtils.copy(scriptContent, new FileWriter( new File(this.projectDir, "build" + this.dsl.getExtension()))); + FileSystemUtils.copyRecursively(new File("src/test/resources/repository"), + new File(this.projectDir, "repository")); GradleRunner gradleRunner = GradleRunner.create().withProjectDir(this.projectDir) .withPluginClasspath(pluginClasspath()); if (this.dsl != Dsl.KOTLIN) { @@ -222,26 +220,17 @@ public String getGradleVersion() { } private static String getBootVersion() { - return evaluateExpression( - "/*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']" - + "/text()"); + return "TEST-SNAPSHOT"; } private static String getDependencyManagementPluginVersion() { - try (FileReader pomReader = new FileReader(".flattened-pom.xml")) { - Document pom = DocumentBuilderFactory.newInstance().newDocumentBuilder() - .parse(new InputSource(pomReader)); - NodeList dependencyElements = pom.getElementsByTagName("dependency"); - for (int i = 0; i < dependencyElements.getLength(); i++) { - Element dependency = (Element) dependencyElements.item(i); - if (dependency.getElementsByTagName("artifactId").item(0).getTextContent() - .equals("dependency-management-plugin")) { - return dependency.getElementsByTagName("version").item(0) - .getTextContent(); - } + try { + URL location = DependencyManagementExtension.class.getProtectionDomain() + .getCodeSource().getLocation(); + try (JarFile jar = new JarFile(new File(location.toURI()))) { + return jar.getManifest().getMainAttributes() + .getValue("Implementation-Version"); } - throw new IllegalStateException( - "dependency management plugin version not found"); } catch (Exception ex) { throw new IllegalStateException( @@ -249,17 +238,4 @@ private static String getDependencyManagementPluginVersion() { } } - private static String evaluateExpression(String expression) { - try (FileReader pomReader = new FileReader(".flattened-pom.xml")) { - XPathFactory xPathFactory = XPathFactory.newInstance(); - XPath xpath = xPathFactory.newXPath(); - XPathExpression expr = xpath.compile(expression); - String version = expr.evaluate(new InputSource(pomReader)); - return version; - } - catch (Exception ex) { - throw new IllegalStateException("Failed to evaluate expression", ex); - } - } - } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests-helpfulErrorWhenVersionlessDependencyFailsToResolve.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests-helpfulErrorWhenVersionlessDependencyFailsToResolve.gradle index 4f9356dd1581..2004d24e14ce 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests-helpfulErrorWhenVersionlessDependencyFailsToResolve.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests-helpfulErrorWhenVersionlessDependencyFailsToResolve.gradle @@ -3,10 +3,6 @@ plugins { id 'org.springframework.boot' version '{version}' } -repositories { - mavenLocal() -} - dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests.gradle index bde30790cc1c..a0c1951204f8 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests.gradle @@ -17,7 +17,7 @@ if (project.hasProperty('applyDependencyManagementPlugin')) { } repositories { - mavenLocal() + maven { url 'file:repository' } } task doesNotHaveDependencyManagement { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinVersionMatchesKotlinPluginVersion.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinVersionPropertyIsSet.gradle similarity index 95% rename from spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinVersionMatchesKotlinPluginVersion.gradle rename to spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinVersionPropertyIsSet.gradle index 4f67100c60c0..47ecadc6b87c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinVersionMatchesKotlinPluginVersion.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinVersionPropertyIsSet.gradle @@ -17,7 +17,7 @@ dependencyManagement { repositories { mavenCentral() - mavenLocal() + maven { url 'file:repository' } } dependencies { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/OnlyDependencyManagementIntegrationTests.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/OnlyDependencyManagementIntegrationTests.gradle index 2fe39651b219..742e1ac9f8ba 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/OnlyDependencyManagementIntegrationTests.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/OnlyDependencyManagementIntegrationTests.gradle @@ -6,7 +6,7 @@ plugins { apply plugin: 'io.spring.dependency-management' repositories { - mavenLocal() + maven { url 'file:repository' } } dependencyManagement { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-duplicatesAreHandledGracefully.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-duplicatesAreHandledGracefully.gradle index f53d0428c5dd..3c649f5cff40 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-duplicatesAreHandledGracefully.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-duplicatesAreHandledGracefully.gradle @@ -18,7 +18,7 @@ sourceSets.all { } repositories { - maven { url "https://repo.spring.io/libs-snapshot" } + mavenCentral() } dependencies { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/repository/org/springframework/boot/spring-boot-dependencies/TEST-SNAPSHOT/spring-boot-dependencies-TEST-SNAPSHOT.pom b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/repository/org/springframework/boot/spring-boot-dependencies/TEST-SNAPSHOT/spring-boot-dependencies-TEST-SNAPSHOT.pom new file mode 100644 index 000000000000..8d4fc766d313 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/repository/org/springframework/boot/spring-boot-dependencies/TEST-SNAPSHOT/spring-boot-dependencies-TEST-SNAPSHOT.pom @@ -0,0 +1,27 @@ + + + 4.0.0 + org.springframework.boot + spring-boot-dependencies + TEST-SNAPSHOT + pom + + 1.7.25 + + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.springframework.boot + spring-boot-starter + TEST-SNAPSHOT + + + +