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:
Rob Winch 2020-03-04 15:14:21 -06:00
parent 034c6c078f
commit 7ad303f0ce
2 changed files with 9 additions and 56 deletions

View File

@ -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");
}
}
}

View File

@ -1,3 +1,5 @@
import java.util.concurrent.Callable
apply plugin: 'io.spring.convention.spring-module'
def includeProject = project(':spring-security-crypto')
@ -34,9 +36,9 @@ dependencies {
testRuntime 'org.hsqldb:hsqldb'
}
task springVersion(type: versions.VersionsResourceTasks) {
versionsFile = file("${buildDir}/versions/spring-security.versions")
versions = provider { ["org.springframework:spring-core":"${springVersion()}"] }
task springVersion(type: org.gradle.api.tasks.WriteProperties) {
outputFile = file("${buildDir}/versions/spring-security.versions")
property("org.springframework:spring-core", springVersion())
}
tasks.processResources {
@ -52,11 +54,11 @@ tasks.sourcesJar.from {includeProject.sourceSets.main.java}
configure(project.tasks.withType(Test)) {
doFirst {
systemProperties['springSecurityVersion'] = version
systemProperties['springVersion'] = springVersion()
systemProperties['springVersion'] = springVersion().call()
}
}
String springVersion() {
return project.configurations.compile.resolvedConfiguration.resolvedArtifacts
.find { it.name == 'spring-core' }.moduleVersion.id.version
Callable<String> springVersion() {
return (Callable<String>) { project.configurations.compile.resolvedConfiguration.resolvedArtifacts
.find { it.name == 'spring-core' }.moduleVersion.id.version }
}