Automatically align version of samples' dependency with main version
This commit enhances the tasks that build the samples to automatically update the version of their spring-restdocs dependency to match the version of the main project.
This commit is contained in:
@@ -20,6 +20,7 @@ import org.gradle.api.GradleException
|
|||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.Task
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.tasks.Exec
|
import org.gradle.api.tasks.Exec
|
||||||
|
import org.gradle.api.tasks.Copy
|
||||||
import org.gradle.api.tasks.GradleBuild
|
import org.gradle.api.tasks.GradleBuild
|
||||||
|
|
||||||
public class SampleBuildConfigurer {
|
public class SampleBuildConfigurer {
|
||||||
@@ -65,6 +66,13 @@ public class SampleBuildConfigurer {
|
|||||||
"${System.env.MAVEN_HOME}/bin/mvn${suffix}" : "mvn${suffix}",
|
"${System.env.MAVEN_HOME}/bin/mvn${suffix}" : "mvn${suffix}",
|
||||||
'clean', 'package']
|
'clean', 'package']
|
||||||
mavenBuild.dependsOn dependencies
|
mavenBuild.dependsOn dependencies
|
||||||
|
|
||||||
|
mavenBuild.doFirst {
|
||||||
|
replaceVersion(new File(this.workingDir, 'pom.xml'),
|
||||||
|
'<spring-restdocs.version>.*</spring-restdocs.version>',
|
||||||
|
"<spring-restdocs.version>${project.version}</spring-restdocs.version>")
|
||||||
|
}
|
||||||
|
|
||||||
return mavenBuild
|
return mavenBuild
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,9 +83,25 @@ public class SampleBuildConfigurer {
|
|||||||
gradleBuild.dir = this.workingDir
|
gradleBuild.dir = this.workingDir
|
||||||
gradleBuild.tasks = ['clean', 'build']
|
gradleBuild.tasks = ['clean', 'build']
|
||||||
gradleBuild.dependsOn dependencies
|
gradleBuild.dependsOn dependencies
|
||||||
|
|
||||||
|
gradleBuild.doFirst {
|
||||||
|
replaceVersion(new File(this.workingDir, 'build.gradle'),
|
||||||
|
"springRestdocsVersion = '.*'",
|
||||||
|
"springRestdocsVersion = '${project.version}'")
|
||||||
|
}
|
||||||
|
|
||||||
return gradleBuild
|
return gradleBuild
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void replaceVersion(File target, String pattern, String replacement) {
|
||||||
|
def lines = target.readLines()
|
||||||
|
target.withWriter { writer ->
|
||||||
|
lines.each { line ->
|
||||||
|
writer.println(line.replaceAll(pattern, replacement))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Task createVerifyIncludes(Project project, File buildDir) {
|
private Task createVerifyIncludes(Project project, File buildDir) {
|
||||||
Task verifyIncludes = project.tasks.create("${name}VerifyIncludes")
|
Task verifyIncludes = project.tasks.create("${name}VerifyIncludes")
|
||||||
verifyIncludes.description = "Verifies the includes in the ${name} sample"
|
verifyIncludes.description = "Verifies the includes in the ${name} sample"
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<java.version>1.7</java.version>
|
<java.version>1.7</java.version>
|
||||||
|
<spring-restdocs.version>1.0.0.BUILD-SNAPSHOT</spring-restdocs.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -49,7 +50,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.restdocs</groupId>
|
<groupId>org.springframework.restdocs</groupId>
|
||||||
<artifactId>spring-restdocs-mockmvc</artifactId>
|
<artifactId>spring-restdocs-mockmvc</artifactId>
|
||||||
<version>1.0.0.BUILD-SNAPSHOT</version>
|
<version>${spring-restdocs.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -124,4 +125,4 @@
|
|||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ group = 'com.example'
|
|||||||
sourceCompatibility = 1.7
|
sourceCompatibility = 1.7
|
||||||
targetCompatibility = 1.7
|
targetCompatibility = 1.7
|
||||||
|
|
||||||
|
ext {
|
||||||
|
snippetsDir = file('build/generated-snippets')
|
||||||
|
springRestdocsVersion = '1.0.0.BUILD-SNAPSHOT'
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
|
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
compile 'org.springframework.boot:spring-boot-starter-hateoas'
|
compile 'org.springframework.boot:spring-boot-starter-hateoas'
|
||||||
@@ -35,11 +40,7 @@ dependencies {
|
|||||||
|
|
||||||
testCompile 'com.jayway.jsonpath:json-path'
|
testCompile 'com.jayway.jsonpath:json-path'
|
||||||
testCompile 'org.springframework.boot:spring-boot-starter-test'
|
testCompile 'org.springframework.boot:spring-boot-starter-test'
|
||||||
testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc:1.0.0.BUILD-SNAPSHOT'
|
testCompile "org.springframework.restdocs:spring-restdocs-mockmvc:$springRestdocsVersion"
|
||||||
}
|
|
||||||
|
|
||||||
ext {
|
|
||||||
snippetsDir = file('build/generated-snippets')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
@@ -61,4 +62,4 @@ jar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eclipseJdt.onlyIf { false }
|
eclipseJdt.onlyIf { false }
|
||||||
cleanEclipseJdt.onlyIf { false }
|
cleanEclipseJdt.onlyIf { false }
|
||||||
|
|||||||
Reference in New Issue
Block a user