mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Fix up-to-date checking of syncAppSource tasks
Previously, the project version was used while filtering the apps source during syncing but it was not considered as an input to the task. This could result in the syncing being skipped even though the project's version had changed. This commit introduces a new custom task to make the configuration more declarative and to allow the necessary input configuration to be done in a single place. Closes gh-28197
This commit is contained in:
parent
1fc52b65a3
commit
8c3820f87e
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2021 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.build;
|
||||||
|
|
||||||
|
import org.gradle.api.DefaultTask;
|
||||||
|
import org.gradle.api.file.DirectoryProperty;
|
||||||
|
import org.gradle.api.model.ObjectFactory;
|
||||||
|
import org.gradle.api.provider.Property;
|
||||||
|
import org.gradle.api.tasks.Input;
|
||||||
|
import org.gradle.api.tasks.InputDirectory;
|
||||||
|
import org.gradle.api.tasks.OutputDirectory;
|
||||||
|
import org.gradle.api.tasks.TaskAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tasks for syncing the source code of a Spring Boot application, filtering its
|
||||||
|
* {@code build.gradle} to set the version of its {@code org.springframework.boot} plugin.
|
||||||
|
*
|
||||||
|
* @author Andy Wilkinson
|
||||||
|
*/
|
||||||
|
public class SyncAppSource extends DefaultTask {
|
||||||
|
|
||||||
|
private final DirectoryProperty sourceDirectory;
|
||||||
|
|
||||||
|
private final DirectoryProperty destinationDirectory;
|
||||||
|
|
||||||
|
private final Property<String> pluginVersion;
|
||||||
|
|
||||||
|
public SyncAppSource() {
|
||||||
|
ObjectFactory objects = getProject().getObjects();
|
||||||
|
this.sourceDirectory = objects.directoryProperty();
|
||||||
|
this.destinationDirectory = objects.directoryProperty();
|
||||||
|
this.pluginVersion = objects.property(String.class)
|
||||||
|
.convention(getProject().provider(() -> getProject().getVersion().toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
void syncAppSources() {
|
||||||
|
getProject().sync((copySpec) -> {
|
||||||
|
copySpec.from(this.sourceDirectory);
|
||||||
|
copySpec.into(this.destinationDirectory);
|
||||||
|
copySpec.filter((line) -> line.replace("id \"org.springframework.boot\"",
|
||||||
|
"id \"org.springframework.boot\" version \"" + getProject().getVersion() + "\""));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@InputDirectory
|
||||||
|
public DirectoryProperty getSourceDirectory() {
|
||||||
|
return this.sourceDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@OutputDirectory
|
||||||
|
public DirectoryProperty getDestinationDirectory() {
|
||||||
|
return this.destinationDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Input
|
||||||
|
public Property<String> getPluginVersion() {
|
||||||
|
return this.pluginVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -30,12 +30,9 @@ task syncMavenRepository(type: Sync) {
|
|||||||
into "${buildDir}/int-test-maven-repository"
|
into "${buildDir}/int-test-maven-repository"
|
||||||
}
|
}
|
||||||
|
|
||||||
task syncAppSource(type: Sync) {
|
task syncAppSource(type: org.springframework.boot.build.SyncAppSource) {
|
||||||
from "spring-boot-launch-script-tests-app"
|
sourceDirectory = file("spring-boot-launch-script-tests-app")
|
||||||
into "${buildDir}/spring-boot-launch-script-tests-app"
|
destinationDirectory = file("${buildDir}/spring-boot-launch-script-tests-app")
|
||||||
filter { line ->
|
|
||||||
line.replace("id \"org.springframework.boot\"", "id \"org.springframework.boot\" version \"${project.version}\"")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task buildApp(type: GradleBuild) {
|
task buildApp(type: GradleBuild) {
|
||||||
|
@ -31,12 +31,9 @@ task syncMavenRepository(type: Sync) {
|
|||||||
into "${buildDir}/int-test-maven-repository"
|
into "${buildDir}/int-test-maven-repository"
|
||||||
}
|
}
|
||||||
|
|
||||||
task syncAppSource(type: Sync) {
|
task syncAppSource(type: org.springframework.boot.build.SyncAppSource) {
|
||||||
from "spring-boot-loader-tests-app"
|
sourceDirectory = file("spring-boot-loader-tests-app")
|
||||||
into "${buildDir}/spring-boot-loader-tests-app"
|
destinationDirectory = file("${buildDir}/spring-boot-loader-tests-app")
|
||||||
filter { line ->
|
|
||||||
line.replace("id \"org.springframework.boot\"", "id \"org.springframework.boot\" version \"${project.version}\"")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task buildApp(type: GradleBuild) {
|
task buildApp(type: GradleBuild) {
|
||||||
|
@ -40,12 +40,9 @@ task syncTestRepository(type: Sync) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task syncAppSource(type: Sync) {
|
task syncAppSource(type: org.springframework.boot.build.SyncAppSource) {
|
||||||
from "spring-boot-server-tests-app"
|
sourceDirectory = file("spring-boot-server-tests-app")
|
||||||
into "${buildDir}/spring-boot-server-tests-app"
|
destinationDirectory = file("${buildDir}/spring-boot-server-tests-app")
|
||||||
filter { line ->
|
|
||||||
line.replace("id \"org.springframework.boot\"", "id \"org.springframework.boot\" version \"${project.version}\"")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task buildApps(type: GradleBuild) {
|
task buildApps(type: GradleBuild) {
|
||||||
|
Loading…
Reference in New Issue
Block a user