Replace VersionsResourceTasks with WriteProperties
VersionsResourceTasks wrote a date comment which prevented this from producing the same result and caused misses in the cache. Closes gh-8114
This commit is contained in:
parent
034c6c078f
commit
7ad303f0ce
|
@ -1,49 +0,0 @@
|
||||||
package versions;
|
|
||||||
|
|
||||||
import org.codehaus.groovy.runtime.ResourceGroovyMethods;
|
|
||||||
import org.gradle.api.DefaultTask;
|
|
||||||
import org.gradle.api.file.RegularFileProperty;
|
|
||||||
import org.gradle.api.provider.MapProperty;
|
|
||||||
import org.gradle.api.tasks.Input;
|
|
||||||
import org.gradle.api.tasks.OutputFile;
|
|
||||||
import org.gradle.api.tasks.TaskAction;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
public class VersionsResourceTasks extends DefaultTask {
|
|
||||||
|
|
||||||
private final RegularFileProperty versionsFile = getProject().getObjects().fileProperty();
|
|
||||||
|
|
||||||
private final MapProperty<String, String> versions = getProject().getObjects().mapProperty(String.class, String.class);
|
|
||||||
|
|
||||||
@OutputFile
|
|
||||||
public RegularFileProperty getVersionsFile() {
|
|
||||||
return versionsFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Input
|
|
||||||
public MapProperty<String, String> getVersions() {
|
|
||||||
return versions;
|
|
||||||
}
|
|
||||||
|
|
||||||
@TaskAction
|
|
||||||
void generateVersions() throws IOException {
|
|
||||||
|
|
||||||
File file = versionsFile.getAsFile().get();
|
|
||||||
File parentFile = versionsFile.getAsFile().get().getParentFile();
|
|
||||||
|
|
||||||
if (parentFile.isDirectory() || parentFile.mkdirs()) {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
properties.putAll(getVersions().get());
|
|
||||||
try (Writer writer = ResourceGroovyMethods.newWriter(file)) {
|
|
||||||
properties.store(writer, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IOException(parentFile + " does not exist and cannot be created");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import java.util.concurrent.Callable
|
||||||
|
|
||||||
apply plugin: 'io.spring.convention.spring-module'
|
apply plugin: 'io.spring.convention.spring-module'
|
||||||
|
|
||||||
def includeProject = project(':spring-security-crypto')
|
def includeProject = project(':spring-security-crypto')
|
||||||
|
@ -34,9 +36,9 @@ dependencies {
|
||||||
testRuntime 'org.hsqldb:hsqldb'
|
testRuntime 'org.hsqldb:hsqldb'
|
||||||
}
|
}
|
||||||
|
|
||||||
task springVersion(type: versions.VersionsResourceTasks) {
|
task springVersion(type: org.gradle.api.tasks.WriteProperties) {
|
||||||
versionsFile = file("${buildDir}/versions/spring-security.versions")
|
outputFile = file("${buildDir}/versions/spring-security.versions")
|
||||||
versions = provider { ["org.springframework:spring-core":"${springVersion()}"] }
|
property("org.springframework:spring-core", springVersion())
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.processResources {
|
tasks.processResources {
|
||||||
|
@ -52,11 +54,11 @@ tasks.sourcesJar.from {includeProject.sourceSets.main.java}
|
||||||
configure(project.tasks.withType(Test)) {
|
configure(project.tasks.withType(Test)) {
|
||||||
doFirst {
|
doFirst {
|
||||||
systemProperties['springSecurityVersion'] = version
|
systemProperties['springSecurityVersion'] = version
|
||||||
systemProperties['springVersion'] = springVersion()
|
systemProperties['springVersion'] = springVersion().call()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String springVersion() {
|
Callable<String> springVersion() {
|
||||||
return project.configurations.compile.resolvedConfiguration.resolvedArtifacts
|
return (Callable<String>) { project.configurations.compile.resolvedConfiguration.resolvedArtifacts
|
||||||
.find { it.name == 'spring-core' }.moduleVersion.id.version
|
.find { it.name == 'spring-core' }.moduleVersion.id.version }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue