Refactor Java and all Groovy Gradle Plugins in buildSrc.
This commit is contained in:
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-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 io.spring.gradle
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.TypeChecked
|
||||
import groovy.transform.TypeCheckingMode
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
/**
|
||||
* Checkout a project template from a git repository.
|
||||
*
|
||||
* @author Marcus Da Coregio
|
||||
*/
|
||||
@CompileStatic
|
||||
abstract class IncludeRepoTask extends DefaultTask {
|
||||
|
||||
private static final String DEFAULT_URI_PREFIX = 'https://github.com/'
|
||||
|
||||
/**
|
||||
* Git repository to use. Will be prefixed with {@link #DEFAULT_URI_PREFIX} if it isn't already
|
||||
* @return
|
||||
*/
|
||||
@Input
|
||||
abstract Property<String> getRepository();
|
||||
|
||||
/**
|
||||
* Git reference to use.
|
||||
*/
|
||||
@Input
|
||||
abstract Property<String> getRef()
|
||||
|
||||
/**
|
||||
* Directory where the project template should be copied.
|
||||
*/
|
||||
@OutputDirectory
|
||||
final File outputDirectory = project.file("$project.buildDir/$name")
|
||||
|
||||
@TaskAction
|
||||
void checkoutAndCopy() {
|
||||
outputDirectory.deleteDir()
|
||||
File checkoutDir = checkout(this, getRemoteUri(), ref.get())
|
||||
moveToOutputDir(checkoutDir, outputDirectory)
|
||||
}
|
||||
|
||||
private static File cleanTemporaryDir(Task task, File tmpDir) {
|
||||
if (tmpDir.exists()) {
|
||||
task.project.delete(tmpDir)
|
||||
}
|
||||
return tmpDir
|
||||
}
|
||||
|
||||
static File checkout(Task task, String remoteUri, String ref) {
|
||||
checkout(task, remoteUri, ref, task.getTemporaryDir())
|
||||
}
|
||||
|
||||
@TypeChecked(TypeCheckingMode.SKIP)
|
||||
static File checkout(Task task, String remoteUri, String ref, File checkoutDir) {
|
||||
cleanTemporaryDir(task, checkoutDir)
|
||||
task.project.exec {
|
||||
commandLine = ["git", "clone", "--no-checkout", remoteUri, checkoutDir.absolutePath]
|
||||
errorOutput = System.err
|
||||
}
|
||||
task.project.exec {
|
||||
commandLine = ["git", "checkout", ref]
|
||||
workingDir = checkoutDir
|
||||
errorOutput = System.err
|
||||
}
|
||||
return checkoutDir
|
||||
}
|
||||
|
||||
private static void moveToOutputDir(File tmpDir, File outputDirectory) {
|
||||
File baseDir = tmpDir
|
||||
baseDir.renameTo(outputDirectory)
|
||||
}
|
||||
|
||||
private String getRemoteUri() {
|
||||
String remoteUri = this.repository.get()
|
||||
if (remoteUri.startsWith(DEFAULT_URI_PREFIX)) {
|
||||
return remoteUri
|
||||
}
|
||||
return DEFAULT_URI_PREFIX + remoteUri
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,12 @@ import org.springframework.gradle.propdeps.PropDepsIdeaPlugin
|
||||
import org.springframework.gradle.propdeps.PropDepsPlugin
|
||||
|
||||
/**
|
||||
* Base Gradle API Plugin for all Spring Java project Gradle Plugins.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
* @see org.gradle.api.Plugin
|
||||
* @see org.gradle.api.Project
|
||||
*/
|
||||
abstract class AbstractSpringJavaPlugin implements Plugin<Project> {
|
||||
|
||||
|
||||
@@ -13,26 +13,33 @@
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package io.spring.gradle.convention
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class ArtifactoryPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
void apply(Project project) {
|
||||
|
||||
project.plugins.apply('com.jfrog.artifactory')
|
||||
String name = Utils.getProjectName(project);
|
||||
|
||||
boolean isSnapshot = Utils.isSnapshot(project);
|
||||
boolean isMilestone = Utils.isMilestone(project);
|
||||
|
||||
project.artifactory {
|
||||
contextUrl = 'https://repo.spring.io'
|
||||
publish {
|
||||
repository {
|
||||
repoKey = isSnapshot ? 'libs-snapshot-local' : isMilestone ? 'libs-milestone-local' : 'libs-release-local'
|
||||
if(project.hasProperty('artifactoryUsername')) {
|
||||
repoKey = isSnapshot ? 'libs-snapshot-local'
|
||||
: isMilestone ? 'libs-milestone-local'
|
||||
: 'libs-release-local'
|
||||
if (project.hasProperty('artifactoryUsername')) {
|
||||
username = artifactoryUsername
|
||||
password = artifactoryPassword
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package io.spring.gradle.convention
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
@@ -24,26 +23,32 @@ import org.gradle.api.plugins.JavaPlugin
|
||||
* Adds and configures Checkstyle plugin.
|
||||
*
|
||||
* @author Vedran Pavic
|
||||
* @author John Blum
|
||||
*/
|
||||
class CheckstylePlugin implements Plugin<Project> {
|
||||
|
||||
final CHECKSTYLE_DIR = 'etc/checkstyle'
|
||||
static final String CHECKSTYLE_PATHNAME = 'etc/checkstyle'
|
||||
|
||||
@Override
|
||||
void apply(Project project) {
|
||||
|
||||
project.plugins.withType(JavaPlugin) {
|
||||
def checkstyleDir = project.rootProject.file(CHECKSTYLE_DIR)
|
||||
if (checkstyleDir.exists() && checkstyleDir.directory) {
|
||||
|
||||
def checkstyleDirectory = project.rootProject.file(CHECKSTYLE_PATHNAME)
|
||||
|
||||
if (checkstyleDirectory.exists() && checkstyleDirectory.directory) {
|
||||
|
||||
project.getPluginManager().apply('checkstyle')
|
||||
project.dependencies.add('checkstyle', 'io.spring.javaformat:spring-javaformat-checkstyle:0.0.29')
|
||||
project.dependencies.add('checkstyle', 'io.spring.nohttp:nohttp-checkstyle:0.0.3.RELEASE')
|
||||
project.dependencies.add('checkstyle',
|
||||
'io.spring.javaformat:spring-javaformat-checkstyle:0.0.29')
|
||||
project.dependencies.add('checkstyle',
|
||||
'io.spring.nohttp:nohttp-checkstyle:0.0.3.RELEASE')
|
||||
|
||||
project.checkstyle {
|
||||
configDirectory = checkstyleDir
|
||||
configDirectory = checkstyleDirectory
|
||||
toolVersion = '8.21'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,61 +1,80 @@
|
||||
/*
|
||||
* Copyright 2016-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 io.spring.gradle.convention
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.artifacts.component.ModuleComponentSelector
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.Internal;
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
/**
|
||||
* Gradle API Task to output all the configured project & subproject (runtime) dependencies.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class DependencyManagementExportTask extends DefaultTask {
|
||||
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
@Internal
|
||||
def projects;
|
||||
|
||||
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension;
|
||||
@Input
|
||||
String getProjectNames() {
|
||||
return this.projects*.name
|
||||
}
|
||||
|
||||
public class DependencyManagementExportTask extends DefaultTask {
|
||||
@Internal
|
||||
def projects;
|
||||
@TaskAction
|
||||
void dependencyManagementExport() throws IOException {
|
||||
|
||||
@Input
|
||||
String getProjectNames() {
|
||||
return projects*.name
|
||||
}
|
||||
def projects = this.projects ?: project.subprojects + project
|
||||
|
||||
@TaskAction
|
||||
public void dependencyManagementExport() throws IOException {
|
||||
def projects = this.projects ?: project.subprojects + project
|
||||
def configurations = projects*.configurations*.findAll { ['testRuntime','integrationTestRuntime','grettyRunnerTomcat8','ajtools'].contains(it.name) }
|
||||
def dependencyResults = configurations*.incoming*.resolutionResult*.allDependencies.flatten()
|
||||
def moduleVersionVersions = dependencyResults.findAll { r -> r.requested instanceof ModuleComponentSelector }.collect { r-> r.selected.moduleVersion }
|
||||
def configurations = projects*.configurations*.findAll {
|
||||
[ 'testRuntime', 'integrationTestRuntime', 'grettyRunnerTomcat10', 'ajtools' ].contains(it.name)
|
||||
}
|
||||
|
||||
def projectDependencies = projects.collect { p-> "${p.group}:${p.name}:${p.version}".toString() } as Set
|
||||
def dependencies = moduleVersionVersions.collect { d ->
|
||||
"${d.group}:${d.name}:${d.version}".toString()
|
||||
}.sort() as Set
|
||||
def dependencyResults = configurations*.incoming*.resolutionResult*.allDependencies.flatten()
|
||||
|
||||
println ''
|
||||
println ''
|
||||
println 'dependencyManagement {'
|
||||
println '\tdependencies {'
|
||||
dependencies.findAll { d-> !projectDependencies.contains(d)}.each {
|
||||
println "\t\tdependency '$it'"
|
||||
}
|
||||
println '\t}'
|
||||
println '}'
|
||||
println ''
|
||||
println ''
|
||||
println 'TIP Use this to find duplicates:\n$ sort gradle/dependency-management.gradle| uniq -c | grep -v \'^\\s*1\''
|
||||
println ''
|
||||
println ''
|
||||
}
|
||||
def moduleVersionVersions = dependencyResults
|
||||
.findAll { r -> r.requested instanceof ModuleComponentSelector }
|
||||
.collect { r -> r.selected.moduleVersion }
|
||||
|
||||
void setOutputFile(File file) throws IOException {
|
||||
this.output = new FileOutputStream(file);
|
||||
}
|
||||
def projectDependencies = projects.collect { p ->
|
||||
"${p.group}:${p.name}:${p.version}".toString()
|
||||
} as Set
|
||||
|
||||
def dependencies = moduleVersionVersions
|
||||
.collect { d -> "${d.group}:${d.name}:${d.version}".toString() }
|
||||
.sort() as Set
|
||||
|
||||
println ''
|
||||
println ''
|
||||
println 'dependencyManagement {'
|
||||
println '\tdependencies {'
|
||||
|
||||
dependencies
|
||||
.findAll { d -> !projectDependencies.contains(d) }
|
||||
.each { println "\t\tdependency '$it'" }
|
||||
|
||||
println '\t}'
|
||||
println '}'
|
||||
println ''
|
||||
println ''
|
||||
println 'TIP Use this to find duplicates:\n$ sort gradle/dependency-management.gradle| uniq -c | grep -v \'^\\s*1\''
|
||||
println ''
|
||||
println ''
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.gradle.api.plugins.JavaPlugin
|
||||
* </ul>
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class DependencySetPlugin implements Plugin<Project> {
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@ package io.spring.gradle.convention
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class DeployDocsPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2002-2017 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 io.spring.gradle.convention
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
@@ -7,7 +22,10 @@ import org.gradle.api.plugins.PluginManager
|
||||
import org.gradle.api.tasks.bundling.Zip
|
||||
|
||||
/**
|
||||
* Aggregates asciidoc, javadoc, and deploying of the docs into a single plugin
|
||||
* Aggregates Asciidoc, Javadoc, and deploying of the docs into a single Gradle Plugin.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class DocsPlugin implements Plugin<Project> {
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-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 io.spring.gradle.convention
|
||||
|
||||
import io.spring.gradle.IncludeRepoTask
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.GradleBuild
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
|
||||
/**
|
||||
* Adds a set of tasks that make easy to clone a remote repository and perform some task
|
||||
*
|
||||
* @author Marcus Da Coregio
|
||||
*/
|
||||
class IncludeCheckRemotePlugin implements Plugin<Project> {
|
||||
@Override
|
||||
void apply(Project project) {
|
||||
IncludeCheckRemoteExtension extension = project.extensions.create('includeCheckRemote', IncludeCheckRemoteExtension)
|
||||
TaskProvider<IncludeRepoTask> includeRepoTask = project.tasks.register('includeRepo', IncludeRepoTask) { IncludeRepoTask it ->
|
||||
it.repository = extension.repository
|
||||
it.ref = extension.ref
|
||||
}
|
||||
project.tasks.register('checkRemote', GradleBuild) {
|
||||
it.dependsOn 'includeRepo'
|
||||
it.dir = includeRepoTask.get().outputDirectory
|
||||
it.tasks = extension.getTasks()
|
||||
}
|
||||
}
|
||||
|
||||
abstract static class IncludeCheckRemoteExtension {
|
||||
|
||||
/**
|
||||
* Git repository to clone
|
||||
*/
|
||||
String repository;
|
||||
|
||||
/**
|
||||
* Git ref to checkout
|
||||
*/
|
||||
String ref
|
||||
|
||||
/**
|
||||
* Task to run in the repository
|
||||
*/
|
||||
List<String> tasks = ['check']
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,8 +26,7 @@ import org.gradle.plugins.ide.idea.IdeaPlugin
|
||||
import org.springframework.gradle.propdeps.PropDepsPlugin
|
||||
|
||||
/**
|
||||
*
|
||||
* Adds support for integration tests to java projects.
|
||||
* Adds support for integration tests to Java projects.
|
||||
*
|
||||
* <ul>
|
||||
* <li>Adds integrationTestCompile and integrationTestRuntime configurations</li>
|
||||
@@ -37,6 +36,7 @@ import org.springframework.gradle.propdeps.PropDepsPlugin
|
||||
* </ul>
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class IntegrationTestPlugin implements Plugin<Project> {
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.gradle.api.plugins.JavaPlugin
|
||||
* Adds a version of jacoco to use and makes check depend on jacocoTestReport.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class JacocoPlugin implements Plugin<Project> {
|
||||
|
||||
|
||||
@@ -1,13 +1,32 @@
|
||||
/*
|
||||
* Copyright 2002-2016 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 io.spring.gradle.convention
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.javadoc.Javadoc
|
||||
|
||||
public class JavadocOptionsPlugin implements Plugin<Project> {
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class JavadocOptionsPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
void apply(Project project) {
|
||||
project.getTasks().withType(Javadoc).all { t->
|
||||
t.options.addStringOption('Xdoclint:none', '-quiet')
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.gradle.convention;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
@@ -23,16 +22,20 @@ import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaTestFixturesPlugin;
|
||||
import org.gradle.api.plugins.PluginContainer;
|
||||
import org.gradle.api.publish.PublishingExtension;
|
||||
import org.gradle.api.publish.VariantVersionMappingStrategy;
|
||||
import org.gradle.api.publish.maven.MavenPublication;
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
|
||||
|
||||
import org.springframework.gradle.propdeps.PropDepsPlugin;
|
||||
|
||||
/**
|
||||
* Creates a Management configuration that is appropriate for adding a platform to that is not exposed externally. If
|
||||
* the JavaPlugin is applied, the compileClasspath, runtimeClasspath, testCompileClasspath, and testRuntimeClasspath
|
||||
* Creates a Management configuration that is appropriate for adding a platform so that it is not exposed externally.
|
||||
*
|
||||
* If the JavaPlugin is applied, the compileClasspath, runtimeClasspath, testCompileClasspath, and testRuntimeClasspath
|
||||
* will extend from it.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
public class ManagementConfigurationPlugin implements Plugin<Project> {
|
||||
|
||||
@@ -40,35 +43,42 @@ public class ManagementConfigurationPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
|
||||
ConfigurationContainer configurations = project.getConfigurations();
|
||||
configurations.create(MANAGEMENT_CONFIGURATION_NAME, (management) -> {
|
||||
management.setVisible(false);
|
||||
|
||||
configurations.create(MANAGEMENT_CONFIGURATION_NAME, management -> {
|
||||
|
||||
management.setCanBeConsumed(false);
|
||||
management.setCanBeResolved(false);
|
||||
management.setVisible(false);
|
||||
|
||||
PluginContainer plugins = project.getPlugins();
|
||||
plugins.withType(JavaPlugin.class, (javaPlugin) -> {
|
||||
|
||||
plugins.withType(JavaPlugin.class, javaPlugin -> {
|
||||
configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME).extendsFrom(management);
|
||||
configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME).extendsFrom(management);
|
||||
configurations.getByName(JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME).extendsFrom(management);
|
||||
configurations.getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME).extendsFrom(management);
|
||||
});
|
||||
plugins.withType(JavaTestFixturesPlugin.class, (javaTestFixturesPlugin) -> {
|
||||
|
||||
plugins.withType(JavaTestFixturesPlugin.class, javaTestFixturesPlugin -> {
|
||||
configurations.getByName("testFixturesCompileClasspath").extendsFrom(management);
|
||||
configurations.getByName("testFixturesRuntimeClasspath").extendsFrom(management);
|
||||
});
|
||||
plugins.withType(MavenPublishPlugin.class, (mavenPublish) -> {
|
||||
|
||||
plugins.withType(MavenPublishPlugin.class, mavenPublish -> {
|
||||
|
||||
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
|
||||
publishing.getPublications().withType(MavenPublication.class, (mavenPublication -> {
|
||||
mavenPublication.versionMapping((versions) ->
|
||||
versions.allVariants(versionMapping -> versionMapping.fromResolutionResult())
|
||||
);
|
||||
}));
|
||||
|
||||
publishing.getPublications().withType(MavenPublication.class, mavenPublication ->
|
||||
mavenPublication.versionMapping(versions ->
|
||||
versions.allVariants(VariantVersionMappingStrategy::fromResolutionResult)));
|
||||
});
|
||||
plugins.withType(PropDepsPlugin.class, (propDepsPlugin -> {
|
||||
|
||||
plugins.withType(PropDepsPlugin.class, propDepsPlugin -> {
|
||||
configurations.getByName("optional").extendsFrom(management);
|
||||
configurations.getByName("provided").extendsFrom(management);
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
/*
|
||||
* Copyright 2002-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 io.spring.gradle.convention
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.JavaPlatformPlugin
|
||||
import org.sonarqube.gradle.SonarQubePlugin
|
||||
import org.springframework.gradle.CopyPropertiesPlugin
|
||||
import org.springframework.gradle.maven.SpringMavenPlugin
|
||||
|
||||
public class MavenBomPlugin implements Plugin<Project> {
|
||||
static String MAVEN_BOM_TASK_NAME = "mavenBom"
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class MavenBomPlugin implements Plugin<Project> {
|
||||
|
||||
public void apply(Project project) {
|
||||
void apply(Project project) {
|
||||
project.plugins.apply(JavaPlatformPlugin)
|
||||
project.plugins.apply(SpringMavenPlugin)
|
||||
project.plugins.apply(CopyPropertiesPlugin)
|
||||
|
||||
@@ -18,12 +18,17 @@ package io.spring.gradle.convention;
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class RepositoryConventionPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
void apply(Project project) {
|
||||
|
||||
String[] forceMavenRepositories = ((String) project.findProperty("forceMavenRepositories"))?.split(',')
|
||||
String[] forceMavenRepositories =
|
||||
((String) project.findProperty("forceMavenRepositories"))?.split(',')
|
||||
|
||||
boolean isImplicitSnapshotRepository = forceMavenRepositories == null && Utils.isSnapshot(project)
|
||||
boolean isImplicitMilestoneRepository = forceMavenRepositories == null && Utils.isMilestone(project)
|
||||
|
||||
@@ -22,6 +22,10 @@ import org.gradle.api.plugins.BasePlugin
|
||||
import org.gradle.api.plugins.PluginManager
|
||||
import org.springframework.gradle.maven.SpringNexusPublishPlugin
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class RootProjectPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
@@ -30,8 +34,8 @@ class RootProjectPlugin implements Plugin<Project> {
|
||||
PluginManager pluginManager = project.getPluginManager()
|
||||
|
||||
pluginManager.apply(BasePlugin)
|
||||
pluginManager.apply(SchemaPlugin)
|
||||
pluginManager.apply(NoHttpPlugin)
|
||||
pluginManager.apply(SchemaPlugin)
|
||||
pluginManager.apply(SpringNexusPublishPlugin)
|
||||
pluginManager.apply("org.sonarqube")
|
||||
|
||||
|
||||
@@ -1,38 +1,60 @@
|
||||
/*
|
||||
* Copyright 2016-2019 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 io.spring.gradle.convention
|
||||
|
||||
import org.gradle.api.plugins.JavaPlugin
|
||||
import org.gradle.api.tasks.bundling.Zip
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
public class SchemaDeployPlugin implements Plugin<Project> {
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class SchemaDeployPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
void apply(Project project) {
|
||||
|
||||
project.getPluginManager().apply('org.hidetake.ssh')
|
||||
|
||||
project.ssh.settings {
|
||||
knownHosts = allowAnyHosts
|
||||
}
|
||||
|
||||
project.remotes {
|
||||
docs {
|
||||
|
||||
retryCount = 5 // Retry 5 times (default is 0)
|
||||
retryWaitSec = 10 // Wait 10 seconds between retries (default is 0)
|
||||
role 'docs'
|
||||
if (project.hasProperty('deployDocsHost')) {
|
||||
host = project.findProperty('deployDocsHost')
|
||||
} else {
|
||||
host = 'docs.af.pivotal.io'
|
||||
}
|
||||
retryCount = 5 // retry 5 times (default is 0)
|
||||
retryWaitSec = 10 // wait 10 seconds between retries (default is 0)
|
||||
|
||||
host = project.hasProperty('deployDocsHost')
|
||||
? project.findProperty('deployDocsHost')
|
||||
: 'docs.af.pivotal.io'
|
||||
|
||||
user = project.findProperty('deployDocsSshUsername')
|
||||
if(project.hasProperty('deployDocsSshKeyPath')) {
|
||||
identity = project.file(project.findProperty('deployDocsSshKeyPath'))
|
||||
} else if (project.hasProperty('deployDocsSshKey')) {
|
||||
identity = project.findProperty('deployDocsSshKey')
|
||||
}
|
||||
if(project.hasProperty('deployDocsSshPassphrase')) {
|
||||
passphrase = project.findProperty('deployDocsSshPassphrase')
|
||||
}
|
||||
|
||||
identity = project.hasProperty('deployDocsSshKeyPath')
|
||||
? project.file(project.findProperty('deployDocsSshKeyPath'))
|
||||
: project.hasProperty('deployDocsSshKey')
|
||||
? project.findProperty('deployDocsSshKey')
|
||||
: identity
|
||||
|
||||
passphrase = project.hasProperty('deployDocsSshPassphrase')
|
||||
? project.findProperty('deployDocsSshPassphrase')
|
||||
: passphrase
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +63,7 @@ public class SchemaDeployPlugin implements Plugin<Project> {
|
||||
doFirst {
|
||||
project.ssh.run {
|
||||
session(project.remotes.docs) {
|
||||
|
||||
def now = System.currentTimeMillis()
|
||||
def name = project.rootProject.name
|
||||
def version = project.rootProject.version
|
||||
@@ -68,4 +91,4 @@ public class SchemaDeployPlugin implements Plugin<Project> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,32 @@
|
||||
/*
|
||||
* Copyright 2016-2019 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 io.spring.gradle.convention
|
||||
|
||||
import org.gradle.api.plugins.JavaPlugin
|
||||
import org.gradle.api.tasks.bundling.Zip
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
public class SchemaPlugin implements Plugin<Project> {
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class SchemaPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getPluginManager().apply(SchemaZipPlugin)
|
||||
void apply(Project project) {
|
||||
project.getPluginManager().apply(SchemaDeployPlugin)
|
||||
project.getPluginManager().apply(SchemaZipPlugin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,64 @@
|
||||
/*
|
||||
* Copyright 2016-2019 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 io.spring.gradle.convention
|
||||
|
||||
import org.gradle.api.plugins.JavaPlugin
|
||||
import org.gradle.api.tasks.bundling.Zip
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.JavaPlugin
|
||||
import org.gradle.api.tasks.bundling.Zip
|
||||
|
||||
public class SchemaZipPlugin implements Plugin<Project> {
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class SchemaZipPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
void apply(Project project) {
|
||||
|
||||
Zip schemaZip = project.tasks.create('schemaZip', Zip)
|
||||
schemaZip.group = 'Distribution'
|
||||
|
||||
schemaZip.archiveBaseName = project.rootProject.name
|
||||
schemaZip.archiveClassifier = 'schema'
|
||||
schemaZip.description = "Builds -${schemaZip.archiveClassifier} archive containing all " +
|
||||
"XSDs for deployment at static.springframework.org/schema."
|
||||
schemaZip.group = 'Distribution'
|
||||
|
||||
project.rootProject.subprojects.each { module ->
|
||||
|
||||
module.getPlugins().withType(JavaPlugin.class).all {
|
||||
def Properties schemas = new Properties();
|
||||
|
||||
module.sourceSets.main.resources.find {
|
||||
it.path.endsWith('META-INF/spring.schemas')
|
||||
}?.withInputStream { schemas.load(it) }
|
||||
Properties schemas = new Properties();
|
||||
|
||||
module.sourceSets.main.resources
|
||||
.find { it.path.endsWith('META-INF/spring.schemas') }
|
||||
?.withInputStream { schemas.load(it) }
|
||||
|
||||
for (def key : schemas.keySet()) {
|
||||
|
||||
def shortName = key.replaceAll(/http.*schema.(.*).spring-.*/, '$1')
|
||||
|
||||
assert shortName != key
|
||||
|
||||
File xsdFile = module.sourceSets.main.resources.find {
|
||||
it.path.endsWith(schemas.get(key))
|
||||
}
|
||||
|
||||
assert xsdFile != null
|
||||
|
||||
schemaZip.into (shortName) {
|
||||
duplicatesStrategy 'exclude'
|
||||
from xsdFile.path
|
||||
|
||||
@@ -24,6 +24,9 @@ import org.gradle.api.Project
|
||||
* <p>
|
||||
* Additionally, if 'gradle/dependency-management.gradle' file is present it will be
|
||||
* automatically applied file for configuring the dependencies.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class SpringDependencyManagementConventionPlugin implements Plugin<Project> {
|
||||
|
||||
@@ -54,5 +57,4 @@ class SpringDependencyManagementConventionPlugin implements Plugin<Project> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,10 @@ import org.gradle.api.plugins.PluginManager
|
||||
import org.springframework.gradle.maven.SpringMavenPlugin
|
||||
|
||||
/**
|
||||
* Defines the Gradle project as a proper Spring Module.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class SpringModulePlugin extends AbstractSpringJavaPlugin {
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.gradle.api.plugins.PluginManager
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class SpringSampleBootPlugin extends SpringSamplePlugin {
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.sonarqube.gradle.SonarQubePlugin;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class SpringSamplePlugin extends AbstractSpringJavaPlugin {
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.gradle.api.tasks.testing.Test
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class SpringSampleWarPlugin extends SpringSamplePlugin {
|
||||
|
||||
@@ -68,16 +69,22 @@ class SpringSampleWarPlugin extends SpringSamplePlugin {
|
||||
project.gretty.integrationTestTask = integrationTest.name
|
||||
|
||||
integrationTest.doFirst {
|
||||
|
||||
def gretty = project.gretty
|
||||
String host = project.gretty.host ?: 'localhost'
|
||||
|
||||
boolean isHttps = gretty.httpsEnabled
|
||||
|
||||
Integer httpPort = integrationTest.systemProperties['gretty.httpPort']
|
||||
Integer httpsPort = integrationTest.systemProperties['gretty.httpsPort']
|
||||
|
||||
int port = isHttps ? httpsPort : httpPort
|
||||
|
||||
String host = project.gretty.host ?: 'localhost'
|
||||
String contextPath = project.gretty.contextPath
|
||||
String httpBaseUrl = "http://${host}:${httpPort}${contextPath}"
|
||||
String httpsBaseUrl = "https://${host}:${httpsPort}${contextPath}"
|
||||
String baseUrl = isHttps ? httpsBaseUrl : httpBaseUrl
|
||||
|
||||
integrationTest.systemProperty 'app.port', port
|
||||
integrationTest.systemProperty 'app.httpPort', httpPort
|
||||
integrationTest.systemProperty 'app.httpsPort', httpsPort
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.gradle.api.Project;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class SpringTestPlugin extends AbstractSpringJavaPlugin {
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.gradle.jvm.tasks.Jar
|
||||
* </code>
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class TestsConfigurationPlugin implements Plugin<Project> {
|
||||
|
||||
|
||||
@@ -1,7 +1,26 @@
|
||||
/*
|
||||
* Copyright 2002-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 io.spring.gradle.convention;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
class Utils {
|
||||
|
||||
private Utils() {}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2002-2017 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.gradle.maven;
|
||||
|
||||
import io.spring.gradle.convention.ArtifactoryPlugin;
|
||||
@@ -6,10 +21,17 @@ import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.PluginManager;
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author John Blum
|
||||
*/
|
||||
public class SpringMavenPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
|
||||
PluginManager pluginManager = project.getPluginManager();
|
||||
|
||||
pluginManager.apply(MavenPublishPlugin.class);
|
||||
pluginManager.apply(SpringSigningPlugin.class);
|
||||
pluginManager.apply(MavenPublishingConventionsPlugin.class);
|
||||
|
||||
@@ -1,27 +1,44 @@
|
||||
/*
|
||||
* Copyright 2002-2016 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.gradle.maven;
|
||||
|
||||
import io.github.gradlenexus.publishplugin.NexusPublishExtension;
|
||||
import io.github.gradlenexus.publishplugin.NexusPublishPlugin;
|
||||
import io.github.gradlenexus.publishplugin.NexusRepository;
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import io.github.gradlenexus.publishplugin.NexusPublishExtension;
|
||||
import io.github.gradlenexus.publishplugin.NexusPublishPlugin;
|
||||
|
||||
public class SpringNexusPublishPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
|
||||
project.getPlugins().apply(NexusPublishPlugin.class);
|
||||
|
||||
NexusPublishExtension nexusPublishing = project.getExtensions().findByType(NexusPublishExtension.class);
|
||||
nexusPublishing.getRepositories().create("ossrh", new Action<NexusRepository>() {
|
||||
@Override
|
||||
public void execute(NexusRepository nexusRepository) {
|
||||
nexusRepository.getNexusUrl().set(URI.create("https://s01.oss.sonatype.org/service/local/"));
|
||||
nexusRepository.getSnapshotRepositoryUrl().set(URI.create("https://s01.oss.sonatype.org/content/repositories/snapshots/"));
|
||||
}
|
||||
|
||||
nexusPublishing.getRepositories().create("ossrh", nexusRepository -> {
|
||||
nexusRepository.getNexusUrl().set(URI.create("https://s01.oss.sonatype.org/service/local/"));
|
||||
nexusRepository.getSnapshotRepositoryUrl()
|
||||
.set(URI.create("https://s01.oss.sonatype.org/content/repositories/snapshots/"));
|
||||
});
|
||||
|
||||
nexusPublishing.getConnectTimeout().set(Duration.ofMinutes(3));
|
||||
nexusPublishing.getClientTimeout().set(Duration.ofMinutes(3));
|
||||
}
|
||||
|
||||
@@ -13,58 +13,57 @@
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package org.springframework.gradle.maven;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.publish.Publication;
|
||||
import org.gradle.api.publish.PublishingExtension;
|
||||
import org.gradle.api.publish.plugins.PublishingPlugin;
|
||||
import org.gradle.plugins.signing.SigningExtension;
|
||||
import org.gradle.plugins.signing.SigningPlugin;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class SpringSigningPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
|
||||
project.getPluginManager().apply(SigningPlugin.class);
|
||||
project.getPlugins().withType(SigningPlugin.class).all(new Action<SigningPlugin>() {
|
||||
@Override
|
||||
public void execute(SigningPlugin signingPlugin) {
|
||||
boolean hasSigningKey = project.hasProperty("signing.keyId") || project.hasProperty("signingKey");
|
||||
if (hasSigningKey) {
|
||||
sign(project);
|
||||
}
|
||||
|
||||
project.getPlugins().withType(SigningPlugin.class).all(signingPlugin -> {
|
||||
|
||||
boolean hasSigningKey = project.hasProperty("signing.keyId")
|
||||
|| project.hasProperty("signingKey");
|
||||
|
||||
if (hasSigningKey) {
|
||||
sign(project);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sign(Project project) {
|
||||
|
||||
SigningExtension signing = project.getExtensions().findByType(SigningExtension.class);
|
||||
signing.setRequired(new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
return project.getGradle().getTaskGraph().hasTask("publishArtifacts");
|
||||
}
|
||||
});
|
||||
String signingKeyId = (String) project.findProperty("signingKeyId");
|
||||
|
||||
signing.setRequired((Callable<Boolean>) () ->
|
||||
project.getGradle().getTaskGraph().hasTask("publishArtifacts"));
|
||||
|
||||
String signingKey = (String) project.findProperty("signingKey");
|
||||
String signingKeyId = (String) project.findProperty("signingKeyId");
|
||||
String signingPassword = (String) project.findProperty("signingPassword");
|
||||
|
||||
if (signingKeyId != null) {
|
||||
signing.useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
signing.useInMemoryPgpKeys(signingKey, signingPassword);
|
||||
}
|
||||
project.getPlugins().withType(PublishAllJavaComponentsPlugin.class).all(new Action<PublishAllJavaComponentsPlugin>() {
|
||||
@Override
|
||||
public void execute(PublishAllJavaComponentsPlugin publishingPlugin) {
|
||||
PublishingExtension publishing = project.getExtensions().findByType(PublishingExtension.class);
|
||||
Publication maven = publishing.getPublications().getByName("mavenJava");
|
||||
signing.sign(maven);
|
||||
}
|
||||
|
||||
project.getPlugins().withType(PublishAllJavaComponentsPlugin.class).all(publishingPlugin -> {
|
||||
PublishingExtension publishing = project.getExtensions().findByType(PublishingExtension.class);
|
||||
Publication maven = publishing.getPublications().getByName("mavenJava");
|
||||
signing.sign(maven);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
implementation-class=io.spring.gradle.convention.IncludeCheckRemotePlugin
|
||||
Reference in New Issue
Block a user