Remove reliance on mavenLocal from Gradle plugin’s tests
See gh-15471
This commit is contained in:
parent
4edc32844a
commit
0ad72d5b5e
|
@ -16,7 +16,6 @@
|
|||
<gradle.executable>./gradlew</gradle.executable>
|
||||
<gradle.task>build</gradle.task>
|
||||
<skip.gradle.build>false</skip.gradle.build>
|
||||
<kotlin.version>1.2.20</kotlin.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
|
|
@ -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<DependencyManagementExtension>().apply {
|
||||
resolutionStrategy {
|
||||
eachDependency {
|
||||
if (requested.group == "org.springframework.boot") {
|
||||
useVersion("{version}")
|
||||
useVersion("TEST-SNAPSHOT")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven {
|
||||
url = uri("file:repository")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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' }
|
||||
}
|
||||
|
|
|
@ -19,12 +19,14 @@ the<DependencyManagementExtension>().apply {
|
|||
resolutionStrategy {
|
||||
eachDependency {
|
||||
if (requested.group == "org.springframework.boot") {
|
||||
useVersion("{version}")
|
||||
useVersion("TEST-SNAPSHOT")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven {
|
||||
url = uri("file:repository")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -6,22 +6,24 @@ plugins {
|
|||
|
||||
apply(plugin = "io.spring.dependency-management")
|
||||
|
||||
the<DependencyManagementExtension>().apply {
|
||||
resolutionStrategy {
|
||||
eachDependency {
|
||||
if (requested.group == "org.springframework.boot") {
|
||||
useVersion("{version}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tag::custom-version[]
|
||||
extra["slf4j.version"] = "1.7.20"
|
||||
// end::custom-version[]
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven {
|
||||
url = uri("file:repository")
|
||||
}
|
||||
}
|
||||
|
||||
the<DependencyManagementExtension>().apply {
|
||||
resolutionStrategy {
|
||||
eachDependency {
|
||||
if (requested.group == "org.springframework.boot") {
|
||||
useVersion("TEST-SNAPSHOT")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task("slf4jVersion") {
|
||||
|
|
|
@ -65,8 +65,8 @@ public class ManagingDependenciesDocumentationTests {
|
|||
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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,12 +43,10 @@ public class KotlinPluginActionIntegrationTests {
|
|||
}
|
||||
|
||||
@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
|
||||
|
|
|
@ -24,33 +24,28 @@ import java.net.URL;
|
|||
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 @@ public class GradleBuild implements TestRule {
|
|||
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 class GradleBuild implements TestRule {
|
|||
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 class GradleBuild implements TestRule {
|
|||
}
|
||||
|
||||
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 @@ public class GradleBuild implements TestRule {
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,10 +3,6 @@ plugins {
|
|||
id 'org.springframework.boot' version '{version}'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ if (project.hasProperty('applyDependencyManagementPlugin')) {
|
|||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven { url 'file:repository' }
|
||||
}
|
||||
|
||||
task doesNotHaveDependencyManagement {
|
||||
|
|
|
@ -17,7 +17,7 @@ dependencyManagement {
|
|||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
maven { url 'file:repository' }
|
||||
}
|
||||
|
||||
dependencies {
|
|
@ -6,7 +6,7 @@ plugins {
|
|||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven { url 'file:repository' }
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
|
|
|
@ -18,7 +18,7 @@ sourceSets.all {
|
|||
}
|
||||
|
||||
repositories {
|
||||
maven { url "https://repo.spring.io/libs-snapshot" }
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>TEST-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<properties>
|
||||
<slf4j.version>1.7.25</slf4j.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>TEST-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
Loading…
Reference in New Issue