Polish the local Spring Build Conventions Gradle Plugins in buildSrc/.

The local Spring Build Conventions Gradle Plugins were copied from the refactored SSDG Spring Build Conventions Gradle Plugins into buildSrc/ and adapted for STDG.
This commit is contained in:
John Blum
2022-03-17 15:50:44 -07:00
parent 28e9d880b2
commit 7fd147b1cb
54 changed files with 1209 additions and 744 deletions

View File

@@ -4,21 +4,23 @@ plugins {
id "groovy" id "groovy"
} }
sourceCompatibility = JavaVersion.VERSION_17
repositories { repositories {
mavenCentral() mavenCentral()
gradlePluginPortal() gradlePluginPortal()
maven { url 'https://repo.spring.io/plugins-release/' } maven {
url 'https://repo.spring.io/plugins-release/'
}
} }
sourceCompatibility = JavaVersion.VERSION_17
sourceSets { sourceSets {
main { main {
java { java {
srcDirs = [] srcDirs = []
} }
groovy { groovy {
srcDirs += ["src/main/java"] srcDirs += [ "src/main/java" ]
} }
} }
} }
@@ -29,10 +31,6 @@ gradlePlugin {
id = "io.spring.convention.management-configuration" id = "io.spring.convention.management-configuration"
implementationClass = "io.spring.gradle.convention.ManagementConfigurationPlugin" implementationClass = "io.spring.gradle.convention.ManagementConfigurationPlugin"
} }
sagan {
id = "org.springframework.security.sagan"
implementationClass = "org.springframework.gradle.sagan.SaganPlugin"
}
githubMilestone { githubMilestone {
id = "org.springframework.github.milestone" id = "org.springframework.github.milestone"
implementationClass = "org.springframework.gradle.github.milestones.GitHubMilestonePlugin" implementationClass = "org.springframework.gradle.github.milestones.GitHubMilestonePlugin"
@@ -41,6 +39,10 @@ gradlePlugin {
id = "org.springframework.propdeps" id = "org.springframework.propdeps"
implementationClass = "org.springframework.gradle.propdeps.PropDepsPlugin" implementationClass = "org.springframework.gradle.propdeps.PropDepsPlugin"
} }
sagan {
id = "org.springframework.sagan"
implementationClass = "org.springframework.gradle.sagan.SaganPlugin"
}
} }
} }
@@ -56,17 +58,14 @@ dependencies {
implementation 'com.apollographql.apollo:apollo-runtime:2.4.5' implementation 'com.apollographql.apollo:apollo-runtime:2.4.5'
implementation 'com.google.code.gson:gson:2.8.8' implementation 'com.google.code.gson:gson:2.8.8'
implementation 'com.github.ben-manes:gradle-versions-plugin:0.38.0'
implementation 'com.github.spullara.mustache.java:compiler:0.9.10'
implementation 'io.github.gradle-nexus:publish-plugin:1.1.0' implementation 'io.github.gradle-nexus:publish-plugin:1.1.0'
implementation 'io.projectreactor:reactor-core:3.4.11' implementation 'io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE'
implementation 'io.spring.nohttp:nohttp-gradle:0.0.9' implementation 'io.spring.javaformat:spring-javaformat-checkstyle:0.0.29'
implementation 'io.spring.gradle:dependency-management-plugin:1.0.10.RELEASE' implementation 'io.spring.nohttp:nohttp-checkstyle:0.0.10'
implementation 'net.sourceforge.htmlunit:htmlunit:2.55.0' implementation 'io.spring.nohttp:nohttp-gradle:0.0.10'
implementation 'net.sourceforge.saxon:saxon:9.1.0.8'
implementation 'org.asciidoctor:asciidoctor-gradle-jvm:3.3.2' implementation 'org.asciidoctor:asciidoctor-gradle-jvm:3.3.2'
implementation 'org.asciidoctor:asciidoctor-gradle-jvm-pdf:3.3.2' implementation 'org.asciidoctor:asciidoctor-gradle-jvm-pdf:3.3.2'
implementation 'org.jfrog.buildinfo:build-info-extractor-gradle:4.24.20' implementation 'org.jfrog.buildinfo:build-info-extractor-gradle:4.27.1'
implementation 'org.hidetake:gradle-ssh-plugin:2.10.1' implementation 'org.hidetake:gradle-ssh-plugin:2.10.1'
implementation 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1' implementation 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1'

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2020 the original author or authors. * Copyright 2015-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
@@ -20,7 +20,7 @@ import org.gradle.api.Project
import org.gradle.api.plugins.GroovyPlugin import org.gradle.api.plugins.GroovyPlugin
import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.PluginManager import org.gradle.api.plugins.PluginManager
import org.gradle.plugins.ide.eclipse.EclipseWtpPlugin import org.gradle.plugins.ide.eclipse.EclipsePlugin
import org.gradle.plugins.ide.idea.IdeaPlugin import org.gradle.plugins.ide.idea.IdeaPlugin
import org.springframework.gradle.CopyPropertiesPlugin import org.springframework.gradle.CopyPropertiesPlugin
import org.springframework.gradle.propdeps.PropDepsEclipsePlugin import org.springframework.gradle.propdeps.PropDepsEclipsePlugin
@@ -28,7 +28,11 @@ import org.springframework.gradle.propdeps.PropDepsIdeaPlugin
import org.springframework.gradle.propdeps.PropDepsPlugin import org.springframework.gradle.propdeps.PropDepsPlugin
/** /**
* Base Gradle API Plugin for all Spring Java project Gradle Plugins. * Abstract base Gradle {@link Plugin} for all Spring Java & Groovy Gradle Plugins used by SBDG.
*
* This abstract base Gradle {@link Plugin} primarily serves to apply a common set of Gradle {@link Plugin Plugins),
* such as the {@link JavaPlugin} and {@link GroovyPlugin} for the various SBDG project Spring modules as well as other
* Spring Gradle {@link Plugin Plugins} to manage builds, IDE integration, releases and so on.
* *
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
@@ -40,31 +44,68 @@ abstract class AbstractSpringJavaPlugin implements Plugin<Project> {
@Override @Override
final void apply(Project project) { final void apply(Project project) {
PluginManager pluginManager = project.getPluginManager() applyPlugins(project)
setJarManifestAttributes(project)
pluginManager.apply(JavaPlugin.class) project.test {
pluginManager.apply(ManagementConfigurationPlugin.class) useJUnitPlatform()
if (project.file("src/main/groovy").exists()
|| project.file("src/test/groovy").exists()
|| project.file("src/integration-test/groovy").exists()) {
pluginManager.apply(GroovyPlugin.class)
} }
pluginManager.apply("io.spring.convention.repository") applyAdditionalPlugins(project)
pluginManager.apply(EclipseWtpPlugin) }
private void applyPlugins(Project project) {
PluginManager pluginManager = project.getPluginManager()
applyJavaPlugin(pluginManager)
applyGroovyPlugin(project)
applyIdePlugins(pluginManager)
applySpringPlugins(pluginManager)
}
@SuppressWarnings("all")
private void applyGroovyPlugin(Project project) {
if (project.file("src/main/groovy").exists()
|| project.file("src/test/groovy").exists()
|| project.file("src/integration-test/groovy").exists()) {
project.getPluginManager().apply(GroovyPlugin.class)
}
}
@SuppressWarnings("all")
private void applyIdePlugins(PluginManager pluginManager) {
pluginManager.apply(EclipsePlugin)
pluginManager.apply(IdeaPlugin) pluginManager.apply(IdeaPlugin)
}
@SuppressWarnings("all")
private void applyJavaPlugin(PluginManager pluginManager) {
pluginManager.apply(JavaPlugin.class)
}
@SuppressWarnings("all")
private void applySpringPlugins(PluginManager pluginManager) {
pluginManager.apply(ManagementConfigurationPlugin)
pluginManager.apply(RepositoryConventionPlugin)
pluginManager.apply(PropDepsPlugin) pluginManager.apply(PropDepsPlugin)
pluginManager.apply(PropDepsEclipsePlugin) pluginManager.apply(PropDepsEclipsePlugin)
pluginManager.apply(PropDepsIdeaPlugin) pluginManager.apply(PropDepsIdeaPlugin)
pluginManager.apply("io.spring.convention.tests-configuration") pluginManager.apply(SpringDependencyManagementConventionsPlugin)
pluginManager.apply("io.spring.convention.integration-test") pluginManager.apply(DependencySetPlugin)
pluginManager.apply("io.spring.convention.springdependencymangement") pluginManager.apply(TestsConfigurationPlugin)
pluginManager.apply("io.spring.convention.dependency-set") pluginManager.apply(IntegrationTestPlugin)
pluginManager.apply("io.spring.convention.javadoc-options") pluginManager.apply(JacocoPlugin);
pluginManager.apply("io.spring.convention.checkstyle") pluginManager.apply(JavadocOptionsPlugin)
pluginManager.apply(CheckstylePlugin)
pluginManager.apply(CopyPropertiesPlugin) pluginManager.apply(CopyPropertiesPlugin)
}
private void setJarManifestAttributes(Project project) {
project.jar { project.jar {
manifest.attributes["Created-By"] = "${System.getProperty("java.version")} (${System.getProperty("java.specification.vendor")})" manifest.attributes["Created-By"] = "${System.getProperty("java.version")} (${System.getProperty("java.specification.vendor")})"
@@ -72,14 +113,8 @@ abstract class AbstractSpringJavaPlugin implements Plugin<Project> {
manifest.attributes["Implementation-Version"] = project.version manifest.attributes["Implementation-Version"] = project.version
manifest.attributes["Automatic-Module-Name"] = project.name.replace('-', '.') manifest.attributes["Automatic-Module-Name"] = project.name.replace('-', '.')
} }
project.test {
useJUnitPlatform()
}
additionalPlugins(project);
} }
protected abstract void additionalPlugins(Project project); protected abstract void applyAdditionalPlugins(Project project);
} }

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
@@ -19,8 +19,13 @@ import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
/** /**
* Applies and configures the JFrag Artifactory Gradle {@link Plugin} to publish Gradle {@link Project} artifacts
* to the Spring {@literal snapshot}, {@literal milestone} and {@literal release} repositories in Artifactory.
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
*/ */
class ArtifactoryPlugin implements Plugin<Project> { class ArtifactoryPlugin implements Plugin<Project> {
@@ -29,17 +34,16 @@ class ArtifactoryPlugin implements Plugin<Project> {
project.plugins.apply('com.jfrog.artifactory') project.plugins.apply('com.jfrog.artifactory')
boolean isSnapshot = Utils.isSnapshot(project); // (Externally-defined) Methods cannot be invoked inside the Groovy/Gradle DSL.
boolean isMilestone = Utils.isMilestone(project); def artifactoryRepoKey = resolveRepositoryKey(project)
def authRequired = isAuthRequired(project)
project.artifactory { project.artifactory {
contextUrl = 'https://repo.spring.io' contextUrl = 'https://repo.spring.io'
publish { publish {
repository { repository {
repoKey = isSnapshot ? 'libs-snapshot-local' repoKey = artifactoryRepoKey
: isMilestone ? 'libs-milestone-local' if (authRequired) {
: 'libs-release-local'
if (project.hasProperty('artifactoryUsername')) {
username = artifactoryUsername username = artifactoryUsername
password = artifactoryPassword password = artifactoryPassword
} }
@@ -50,4 +54,20 @@ class ArtifactoryPlugin implements Plugin<Project> {
} }
} }
} }
@SuppressWarnings("all")
private boolean isAuthRequired(Project project) {
project?.hasProperty('artifactoryUsername')
}
@SuppressWarnings("all")
private String resolveRepositoryKey(Project project) {
boolean isSnapshot = Utils.isSnapshot(project);
boolean isMilestone = Utils.isMilestone(project);
return isSnapshot ? 'libs-snapshot-local'
: isMilestone ? 'libs-milestone-local'
: 'libs-release-local'
}
} }

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2016-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
@@ -20,14 +20,17 @@ import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPlugin
/** /**
* Adds and configures Checkstyle plugin. * Configures and applies the Checkstyle Gradle {@link Plugin}.
* *
* @author Vedran Pavic * @author Vedran Pavic
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
*/ */
class CheckstylePlugin implements Plugin<Project> { class CheckstylePlugin implements Plugin<Project> {
static final String CHECKSTYLE_PATHNAME = 'etc/checkstyle' static final String CHECKSTYLE_PATHNAME = 'etc/checkstyle'
static final String CHECKSTYLE_VERSION = '8.21'
@Override @Override
void apply(Project project) { void apply(Project project) {
@@ -36,17 +39,15 @@ class CheckstylePlugin implements Plugin<Project> {
def checkstyleDirectory = project.rootProject.file(CHECKSTYLE_PATHNAME) def checkstyleDirectory = project.rootProject.file(CHECKSTYLE_PATHNAME)
if (checkstyleDirectory.exists() && checkstyleDirectory.directory) { if (checkstyleDirectory?.isDirectory()) {
project.getPluginManager().apply('checkstyle') project.getPluginManager().apply('checkstyle')
project.dependencies.add('checkstyle', project.dependencies.add('checkstyle', 'io.spring.javaformat:spring-javaformat-checkstyle')
'io.spring.javaformat:spring-javaformat-checkstyle:0.0.29') project.dependencies.add('checkstyle', 'io.spring.nohttp:nohttp-checkstyle')
project.dependencies.add('checkstyle',
'io.spring.nohttp:nohttp-checkstyle:0.0.3.RELEASE')
project.checkstyle { project.checkstyle {
configDirectory = checkstyleDirectory configDirectory = checkstyleDirectory
toolVersion = '8.21' toolVersion = CHECKSTYLE_VERSION
} }
} }
} }

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2016-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
@@ -22,7 +22,7 @@ import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskAction
/** /**
* Gradle API Task to output all the configured project & subproject (runtime) dependencies. * Gradle API Task to output all the configured project &amp; subproject (runtime) dependencies.
* *
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
@@ -43,7 +43,7 @@ class DependencyManagementExportTask extends DefaultTask {
def projects = this.projects ?: project.subprojects + project def projects = this.projects ?: project.subprojects + project
def configurations = projects*.configurations*.findAll { def configurations = projects*.configurations*.findAll {
[ 'testRuntime', 'integrationTestRuntime', 'grettyRunnerTomcat10', 'ajtools' ].contains(it.name) [ 'testRuntimeOnly', 'integrationTestRuntime', 'grettyRunnerTomcat10', 'ajtools' ].contains(it.name)
} }
def dependencyResults = configurations*.incoming*.resolutionResult*.allDependencies.flatten() def dependencyResults = configurations*.incoming*.resolutionResult*.allDependencies.flatten()

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
@@ -20,17 +20,24 @@ import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPlugin
/** /**
* Adds sets of dependencies to make it easy to add a grouping of dependencies. The * Defines sets of dependencies to make it easy to add a related group of dependencies to a Gradle {@link Project}.
* dependencies added are: *
* The dependencies set defined include:
* *
* <ul> * <ul>
* <li>jstlDependencies</li> * <li>jstlDependencies</li>
* <li>seleniumDependencies</li> * <li>seleniumDependencies</li>
* <li>slf4jDependencies</li> * <li>slf4jDependencies</li>
* <li>testDependencies</li>
* </ul> * </ul>
* *
*{@literal testDependencies} are automatically added to Java projects
* ({@lin Project Projects} with the {@link JavaPlugin} applied).
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
*/ */
class DependencySetPlugin implements Plugin<Project> { class DependencySetPlugin implements Plugin<Project> {
@@ -50,6 +57,7 @@ class DependencySetPlugin implements Plugin<Project> {
project.ext.slf4jDependencies = [ project.ext.slf4jDependencies = [
"org.slf4j:slf4j-api", "org.slf4j:slf4j-api",
"org.slf4j:jcl-over-slf4j", "org.slf4j:jcl-over-slf4j",
"org.slf4j:jul-to-slf4j",
"org.slf4j:log4j-over-slf4j", "org.slf4j:log4j-over-slf4j",
"ch.qos.logback:logback-classic" "ch.qos.logback:logback-classic"
] ]

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
@@ -24,6 +24,8 @@ import org.gradle.api.Project
*/ */
class DeployDocsPlugin implements Plugin<Project> { class DeployDocsPlugin implements Plugin<Project> {
static final String DEFAULT_SPRING_DOCS_HOST = 'docs-ip.spring.io';
@Override @Override
void apply(Project project) { void apply(Project project) {
@@ -42,7 +44,7 @@ class DeployDocsPlugin implements Plugin<Project> {
host = project.hasProperty('deployDocsHost') host = project.hasProperty('deployDocsHost')
? project.findProperty('deployDocsHost') ? project.findProperty('deployDocsHost')
: 'docs-ip.spring.io' : DEFAULT_SPRING_DOCS_HOST
user = project.findProperty('deployDocsSshUsername') user = project.findProperty('deployDocsSshUsername')
@@ -50,17 +52,18 @@ class DeployDocsPlugin implements Plugin<Project> {
? project.file(project.findProperty('deployDocsSshKeyPath')) ? project.file(project.findProperty('deployDocsSshKeyPath'))
: project.hasProperty('deployDocsSshKey') : project.hasProperty('deployDocsSshKey')
? project.findProperty('deployDocsSshKey') ? project.findProperty('deployDocsSshKey')
: identity : null
passphrase = project.hasProperty('deployDocsSshPassphrase') passphrase = project.hasProperty('deployDocsSshPassphrase')
? project.findProperty('deployDocsSshPassphrase') ? project.findProperty('deployDocsSshPassphrase')
: passphrase : null
} }
} }
project.task('deployDocs') { project.task('deployDocs') {
dependsOn 'docsZip' dependsOn 'docs'
doFirst { doLast {
project.ssh.run { project.ssh.run {
session(project.remotes.docs) { session(project.remotes.docs) {
@@ -71,18 +74,20 @@ class DeployDocsPlugin implements Plugin<Project> {
execute "mkdir -p $tempPath" execute "mkdir -p $tempPath"
project.tasks.docsZip.outputs.each { o -> project.tasks.docsZip.outputs.each { out ->
put from: o.files, into: tempPath put from: out.files, into: tempPath
} }
execute "unzip $tempPath*.zip -d $tempPath" execute "unzip $tempPath*.zip -d $tempPath"
def extractPath = "/var/www/domains/spring.io/docs/htdocs/autorepo/docs/${name}/${version}/" def extractPath =
"/var/www/domains/spring.io/docs/htdocs/autorepo/docs/${name}/${version}/"
execute "rm -rf $extractPath" execute "rm -rf $extractPath"
execute "mkdir -p $extractPath" execute "mkdir -p $extractPath"
execute "mv $tempPath/docs/* $extractPath" execute "mv $tempPath/docs/* $extractPath"
execute "chmod -R g+w $extractPath" execute "chmod -R g+w $extractPath"
} }
} }
} }

View File

@@ -1,23 +1,24 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.Task import org.gradle.api.Task
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.plugins.PluginManager import org.gradle.api.plugins.PluginManager
import org.gradle.api.tasks.bundling.Zip import org.gradle.api.tasks.bundling.Zip
@@ -32,28 +33,40 @@ class DocsPlugin implements Plugin<Project> {
@Override @Override
void apply(Project project) { void apply(Project project) {
PluginManager pluginManager = project.getPluginManager(); PluginManager pluginManager = project.getPluginManager()
pluginManager.apply("org.asciidoctor.jvm.convert"); pluginManager.apply("org.asciidoctor.jvm.convert")
pluginManager.apply("org.asciidoctor.jvm.pdf"); pluginManager.apply("org.asciidoctor.jvm.pdf")
pluginManager.apply(AsciidoctorConventionPlugin); pluginManager.apply(AsciidoctorConventionPlugin)
pluginManager.apply(DeployDocsPlugin); pluginManager.apply(DeployDocsPlugin)
pluginManager.apply(JavadocApiPlugin); pluginManager.apply(JavadocApiPlugin)
def projectName = Utils.getProjectName(project);
def pdfFilename = projectName + '-reference.pdf';
Task docsZip = project.tasks.create('docsZip', Zip) { Task docsZip = project.tasks.create('docsZip', Zip) {
archiveBaseName = project.rootProject.name archiveBaseName = project.rootProject.name
archiveClassifier = 'docs' archiveClassifier = 'docs'
group = 'Distribution' group = 'Distribution'
description = "Builds -${archiveClassifier} archive containing all Docs for deployment at docs.spring.io." description = "Builds -${archiveClassifier} archive containing all documenation for deployment to docs-ip.spring.io."
dependsOn 'api', 'asciidoctor' dependsOn 'api', 'asciidoctor'
from(project.tasks.api.outputs) { from(project.tasks.api.outputs) {
into 'api' into 'api'
} }
from(project.tasks.asciidoctor.outputs) {
into 'reference/html5'
include '**'
}
from(project.tasks.asciidoctorPdf.outputs) {
into 'reference/pdf'
include '**'
rename "index.pdf", pdfFilename
}
into 'docs' into 'docs'
duplicatesStrategy 'exclude' duplicatesStrategy DuplicatesStrategy.EXCLUDE
} }
Task docs = project.tasks.create("docs") { Task docs = project.tasks.create("docs") {
@@ -63,5 +76,6 @@ class DocsPlugin implements Plugin<Project> {
} }
project.tasks.assemble.dependsOn docs project.tasks.assemble.dependsOn docs
} }
} }

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2016-2018 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
@@ -26,17 +26,21 @@ import org.gradle.plugins.ide.idea.IdeaPlugin
import org.springframework.gradle.propdeps.PropDepsPlugin import org.springframework.gradle.propdeps.PropDepsPlugin
/** /**
* Adds support for integration tests to Java projects. * Adds Integration Test support to Java projects.
* *
* <ul> * <ul>
* <li>Adds integrationTestCompile and integrationTestRuntime configurations</li> * <li>Adds integrationTestCompile and integrationTestRuntimeOnly configurations</li>
* <li>A new source test folder of src/integration-test/java has been added</li> * <li>Adds new source test folder of src/integration-test/java</li>
* <li>A task to run integration tests named integrationTest is added</li> * <li>Adds a task to run integration tests named integrationTest</li>
* <li>If Groovy plugin is added a new source test folder src/integration-test/groovy is added</li> * <li>Adds a new source test folder src/integration-test/groovy if the Groovy Plugin was added</li>
* </ul> * </ul>
* *
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
* @see org.gradle.api.Task
* @see org.gradle.api.tasks.testing.Test
*/ */
class IntegrationTestPlugin implements Plugin<Project> { class IntegrationTestPlugin implements Plugin<Project> {
@@ -47,79 +51,83 @@ class IntegrationTestPlugin implements Plugin<Project> {
} }
} }
private applyJava(Project project) { private void applyJava(Project project) {
if (!project.file('src/integration-test/').exists()) { // Do not add any configuration if there are no (integration) tests to avoid adding Gretty.
// Do not add any configuration if there are no (integration) tests to avoid adding Gretty. if (isIntegrationTestSourceAvailable(project)) {
return
}
project.configurations { project.configurations {
integrationTestCompile { integrationTestCompile {
extendsFrom testImplementation extendsFrom testCompileClasspath
} }
integrationTestRuntime { integrationTestRuntime {
extendsFrom integrationTestCompile, testRuntime, testRuntimeOnly extendsFrom integrationTestCompile, testRuntimeOnly
}
}
project.sourceSets {
integrationTest {
java.srcDir project.file('src/integration-test/java')
resources.srcDir project.file('src/integration-test/resources')
compileClasspath = project.sourceSets.main.output + project.sourceSets.test.output + project.configurations.integrationTestCompile
runtimeClasspath = output + compileClasspath + project.configurations.integrationTestRuntime
}
}
Task integrationTestTask = project.tasks.create("integrationTest", Test) {
group = 'Verification'
description = 'Runs the integration tests.'
dependsOn 'jar'
testClassesDirs = project.sourceSets.integrationTest.output.classesDirs
classpath = project.sourceSets.integrationTest.runtimeClasspath
shouldRunAfter project.tasks.test
useJUnitPlatform()
}
project.tasks.check.dependsOn integrationTestTask
project.plugins.withType(IdeaPlugin) {
project.idea {
module {
testSourceDirs += project.file('src/integration-test/java')
scopes.TEST.plus += [ project.configurations.integrationTestCompile ]
} }
} }
}
project.plugins.withType(GroovyPlugin) {
project.sourceSets { project.sourceSets {
integrationTest { integrationTest {
groovy.srcDirs project.file('src/integration-test/groovy') java.srcDir project.file('src/integration-test/java')
resources.srcDir project.file('src/integration-test/resources')
compileClasspath = project.sourceSets.main.output + project.sourceSets.test.output + project.configurations.integrationTestCompile
runtimeClasspath = output + compileClasspath + project.configurations.integrationTestRuntime
} }
} }
Task integrationTestTask = project.tasks.create("integrationTest", Test) {
group = 'Verification'
description = 'Runs Integration Tests'
dependsOn 'jar'
testClassesDirs = project.sourceSets.integrationTest.output.classesDirs
classpath = project.sourceSets.integrationTest.runtimeClasspath
shouldRunAfter project.tasks.test
useJUnitPlatform()
}
project.tasks.check.dependsOn integrationTestTask
project.plugins.withType(EclipsePlugin) {
project.eclipse.classpath {
plusConfigurations += [ project.configurations.integrationTestCompile ]
}
}
project.plugins.withType(IdeaPlugin) { project.plugins.withType(IdeaPlugin) {
project.idea { project.idea {
module { module {
testSourceDirs += project.file('src/integration-test/groovy') testSourceDirs += project.file('src/integration-test/java')
scopes.TEST.plus += [ project.configurations.integrationTestCompile ]
}
}
}
project.plugins.withType(GroovyPlugin) {
project.sourceSets {
integrationTest {
groovy.srcDirs project.file('src/integration-test/groovy')
}
}
project.plugins.withType(IdeaPlugin) {
project.idea {
module {
testSourceDirs += project.file('src/integration-test/groovy')
}
}
}
}
project.plugins.withType(PropDepsPlugin) {
project.configurations {
integrationTestCompile {
extendsFrom optional, provided
} }
} }
} }
} }
}
project.plugins.withType(PropDepsPlugin) { @SuppressWarnings("all")
project.configurations { private boolean isIntegrationTestSourceAvailable(Project project) {
integrationTestCompile { return project.file('src/integration-test/').exists()
extendsFrom optional, provided
}
}
}
project.plugins.withType(EclipsePlugin) {
project.eclipse.classpath {
plusConfigurations += [ project.configurations.integrationTestCompile ]
}
}
} }
} }

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2016-2018 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
@@ -20,13 +20,18 @@ import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPlugin
/** /**
* Adds a version of jacoco to use and makes check depend on jacocoTestReport. * Applies the Jacoco Gradle {@link Plugin} to the target Gradle {@link Project}
* and configures {@literal check} Gradle Task to depend on the {@literal jacocoTestReport} Gradle Task.
* *
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
*/ */
class JacocoPlugin implements Plugin<Project> { class JacocoPlugin implements Plugin<Project> {
private static final String JACOCO_VERSION = '0.8.7';
@Override @Override
void apply(Project project) { void apply(Project project) {
@@ -36,7 +41,7 @@ class JacocoPlugin implements Plugin<Project> {
project.tasks.check.dependsOn project.tasks.jacocoTestReport project.tasks.check.dependsOn project.tasks.jacocoTestReport
project.jacoco { project.jacoco {
toolVersion = '0.8.7' toolVersion = JACOCO_VERSION
} }
} }
} }

View File

@@ -1,35 +1,40 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
import java.util.regex.Pattern
import org.gradle.api.Action
import org.gradle.api.JavaVersion import org.gradle.api.JavaVersion
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.javadoc.Javadoc import org.gradle.api.tasks.javadoc.Javadoc
import org.slf4j.Logger import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.util.regex.Pattern
/** /**
* Generates Javadoc API documentation for {@literal this} {@link Project}.
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
* @see org.gradle.api.plugins.JavaPluginExtension
* @see org.gradle.api.tasks.javadoc.Javadoc
*/ */
class JavadocApiPlugin implements Plugin<Project> { class JavadocApiPlugin implements Plugin<Project> {
@@ -45,7 +50,7 @@ class JavadocApiPlugin implements Plugin<Project> {
Javadoc api = project.tasks.create("api", Javadoc) Javadoc api = project.tasks.create("api", Javadoc)
api.setGroup("Documentation") api.setGroup("Documentation")
api.setDescription("Generates aggregated Javadoc API documentation.") api.setDescription("Generates Javadoc API documentation.")
api.setDestinationDir(new File(project.getBuildDir(), "api")) api.setDestinationDir(new File(project.getBuildDir(), "api"))
api.setMaxMemory("1024m") api.setMaxMemory("1024m")
@@ -80,26 +85,22 @@ class JavadocApiPlugin implements Plugin<Project> {
excludes.each {this.excludes.add(Pattern.compile(it)) } excludes.each {this.excludes.add(Pattern.compile(it)) }
} }
private void addProject(Javadoc api, Project project) { private void addProject(Javadoc javadoc, Project project) {
if (isProjectIncluded(project)) { if (isProjectIncluded(project)) {
logInfo("Add sources for project {}", project) logInfo("Add sources for project {}", project)
project.getPlugins().withType(SpringModulePlugin.class).all { plugin -> project.getPlugins().withType(SpringModulePlugin).all { plugin ->
JavaPluginExtension java = project.getExtensions().getByType(JavaPluginExtension)
JavaPluginConvention java = project.getConvention().getPlugin(JavaPluginConvention.class)
SourceSet mainSourceSet = java.getSourceSets().getByName("main") SourceSet mainSourceSet = java.getSourceSets().getByName("main")
api.setSource(api.getSource().plus(mainSourceSet.getAllJava())) javadoc.setSource(javadoc.getSource() + mainSourceSet.getAllJava())
project.getTasks().withType(Javadoc.class).all(new Action<Javadoc>() { project.getTasks().withType(Javadoc).all((Javadoc javadocTask) ->
javadoc.setClasspath(javadoc.getClasspath() + javadocTask.getClasspath()))
@Override
void execute(Javadoc projectJavadoc) {
api.setClasspath(api.getClasspath().plus(projectJavadoc.getClasspath()))
}
})
} }
} }
} }

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
@@ -20,15 +20,23 @@ import org.gradle.api.Project
import org.gradle.api.tasks.javadoc.Javadoc import org.gradle.api.tasks.javadoc.Javadoc
/** /**
* Configures Javadoc (Gradle Task) to disable the DocLint tool by setting the {@literal -Xdoclint} JVM extension option
* to {@literal none} as well as setting the {@literal -quiet} Javadoc option thereby suppressing the output from
* the Javadoc tool.
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
* @see org.gradle.api.tasks.javadoc.Javadoc
*/ */
class JavadocOptionsPlugin implements Plugin<Project> { class JavadocOptionsPlugin implements Plugin<Project> {
@Override @Override
void apply(Project project) { void apply(Project project) {
project.getTasks().withType(Javadoc).all { t->
t.options.addStringOption('Xdoclint:none', '-quiet') project.getTasks().withType(Javadoc).all { task ->
task.options.addStringOption('Xdoclint:none', '-quiet')
} }
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ package io.spring.gradle.convention;
import org.gradle.api.Plugin; import org.gradle.api.Plugin;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaTestFixturesPlugin; import org.gradle.api.plugins.JavaTestFixturesPlugin;
@@ -29,18 +30,22 @@ import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
import org.springframework.gradle.propdeps.PropDepsPlugin; import org.springframework.gradle.propdeps.PropDepsPlugin;
/** /**
* Creates a Management configuration that is appropriate for adding a platform so that it is not exposed externally. * Creates a {@literal Management} Gradle {@link Configuration} that is appropriate for adding a platform
* that it is not exposed externally.
* *
* If the JavaPlugin is applied, the compileClasspath, runtimeClasspath, testCompileClasspath, and testRuntimeClasspath * If the {@link JavaPlugin} is applied, then the {@literal compileClasspath}, {@literal runtimeClasspath},
* will extend from it. * {@literal testCompileClasspath}, and {@literal testRuntimeClasspath} will extend from it.
* *
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
*/ */
public class ManagementConfigurationPlugin implements Plugin<Project> { public class ManagementConfigurationPlugin implements Plugin<Project> {
public static final String MANAGEMENT_CONFIGURATION_NAME = "management"; public static final String MANAGEMENT_CONFIGURATION_NAME = "management";
// TODO: Understand why we don't want certain Configurations to be consumed, resolved or visible???
@Override @Override
public void apply(Project project) { public void apply(Project project) {
@@ -66,11 +71,11 @@ public class ManagementConfigurationPlugin implements Plugin<Project> {
configurations.getByName("testFixturesRuntimeClasspath").extendsFrom(management); configurations.getByName("testFixturesRuntimeClasspath").extendsFrom(management);
}); });
plugins.withType(MavenPublishPlugin.class, mavenPublish -> { plugins.withType(MavenPublishPlugin.class, mavenPublishPlugin -> {
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class); PublishingExtension publishingExtension = project.getExtensions().getByType(PublishingExtension.class);
publishing.getPublications().withType(MavenPublication.class, mavenPublication -> publishingExtension.getPublications().withType(MavenPublication.class, mavenPublication ->
mavenPublication.versionMapping(versions -> mavenPublication.versionMapping(versions ->
versions.allVariants(VariantVersionMappingStrategy::fromResolutionResult))); versions.allVariants(VariantVersionMappingStrategy::fromResolutionResult)));
}); });

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -18,18 +18,28 @@ package io.spring.gradle.convention
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlatformPlugin import org.gradle.api.plugins.JavaPlatformPlugin
import org.gradle.api.plugins.PluginManager
import org.springframework.gradle.CopyPropertiesPlugin import org.springframework.gradle.CopyPropertiesPlugin
import org.springframework.gradle.maven.SpringMavenPlugin import org.springframework.gradle.maven.SpringMavenPlugin
/** /**
* Gradle {@link Plugin} used to generate a Maven BOM for the Gradle {@link Project}.
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
*/ */
class MavenBomPlugin implements Plugin<Project> { class MavenBomPlugin implements Plugin<Project> {
@Override
void apply(Project project) { void apply(Project project) {
project.plugins.apply(JavaPlatformPlugin)
project.plugins.apply(SpringMavenPlugin) PluginManager pluginManager = project.getPluginManager();
project.plugins.apply(CopyPropertiesPlugin)
pluginManager.apply(JavaPlatformPlugin)
pluginManager.apply(SpringMavenPlugin)
pluginManager.apply(CopyPropertiesPlugin)
} }
} }

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2016-2018 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention; package io.spring.gradle.convention;
@@ -19,8 +19,13 @@ import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
/** /**
* Declares Maven Repositories (for example: mavenLocal(), mavenCentral(), jcenter(), Spring Repositories, etc)
* based on a {@link Project Project's} release artifact(s).
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
*/ */
class RepositoryConventionPlugin implements Plugin<Project> { class RepositoryConventionPlugin implements Plugin<Project> {

View File

@@ -1,36 +1,53 @@
/* /*
* Copyright 2016-2019 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
import io.spring.nohttp.gradle.NoHttpPlugin import io.spring.nohttp.gradle.NoHttpPlugin
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.plugins.BasePlugin import org.gradle.api.plugins.BasePlugin
import org.gradle.api.plugins.PluginManager import org.gradle.api.plugins.PluginManager
import org.springframework.gradle.maven.SpringNexusPublishPlugin import org.springframework.gradle.maven.SpringNexusPublishPlugin
/** /**
* The Gradle {@link Plugin} applied to the {@literal root} Gradle {@link Project} with functionality inherited by
* all Gradle {@link Project Projects} ({@literal sub-projects} in a multi-module project.
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
*/ */
class RootProjectPlugin implements Plugin<Project> { class RootProjectPlugin implements Plugin<Project> {
@Override @Override
void apply(Project project) { void apply(Project project) {
applyPlugins(project)
configureMavenCentralRepository(project)
configureResolutionStrategy(project)
configureSonarQube(project)
createDependencyManagementExportTask(project)
createReleasePublishedArtifactsTask(project)
}
@SuppressWarnings("all")
private void applyPlugins(Project project) {
PluginManager pluginManager = project.getPluginManager() PluginManager pluginManager = project.getPluginManager()
pluginManager.apply(BasePlugin) pluginManager.apply(BasePlugin)
@@ -38,24 +55,40 @@ class RootProjectPlugin implements Plugin<Project> {
pluginManager.apply(SchemaPlugin) pluginManager.apply(SchemaPlugin)
pluginManager.apply(SpringNexusPublishPlugin) pluginManager.apply(SpringNexusPublishPlugin)
pluginManager.apply("org.sonarqube") pluginManager.apply("org.sonarqube")
}
/**
* Adds the Maven Central Repository to the list of repositories used by this Gradle {@link Project} build
* to resolve dependencies.
*
* @param project Gradle {@link Project}.
* @see org.gradle.api.Project
*/
@SuppressWarnings("all")
private void configureMavenCentralRepository(Project project) {
project.repositories.mavenCentral() project.repositories.mavenCentral()
}
project.allprojects { private void configureResolutionStrategy(Project project) {
configurations.all {
resolutionStrategy { project.allprojects {
cacheChangingModulesFor 0, "seconds" configurations.all {
cacheDynamicVersionsFor 0, "seconds" resolutionStrategy {
} cacheChangingModulesFor 0, 'seconds'
} cacheDynamicVersionsFor 0, 'seconds'
} }
}
}
}
private void configureSonarQube(Project project) {
String projectName = Utils.getProjectName(project) String projectName = Utils.getProjectName(project)
project.sonarqube { project.sonarqube {
properties { properties {
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.projectName", projectName property "sonar.projectName", projectName
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.jacoco.reportPath", "${project.buildDir.name}/jacoco.exec" property "sonar.jacoco.reportPath", "${project.buildDir.name}/jacoco.exec"
property "sonar.links.homepage", "https://spring.io/${projectName}" property "sonar.links.homepage", "https://spring.io/${projectName}"
property "sonar.links.ci", "https://jenkins.spring.io/job/${projectName}/" property "sonar.links.ci", "https://jenkins.spring.io/job/${projectName}/"
@@ -64,13 +97,24 @@ class RootProjectPlugin implements Plugin<Project> {
property "sonar.links.scm_dev", "https://github.com/spring-projects/${projectName}.git" property "sonar.links.scm_dev", "https://github.com/spring-projects/${projectName}.git"
} }
} }
}
project.tasks.create("dependencyManagementExport", DependencyManagementExportTask) @SuppressWarnings("all")
private void createDependencyManagementExportTask(Project project) {
project.tasks.create("dependencyManagementExport", DependencyManagementExportTask)
}
def finalizeDeployArtifacts = project.task("finalizeDeployArtifacts") private void createReleasePublishedArtifactsTask(Project project) {
if (Utils.isRelease(project) && project.hasProperty("ossrhUsername")) { project.task("releasePublishedArtifacts", { Task releasePublishedArtifacts ->
finalizeDeployArtifacts.dependsOn project.tasks.closeAndReleaseOssrhStagingRepository if (isReleasingToMavenCentral(project)) {
} releasePublishedArtifacts.dependsOn project.tasks.closeAndReleaseOssrhStagingRepository
}
})
}
@SuppressWarnings("all")
private boolean isReleasingToMavenCentral(Project project) {
Utils.isRelease(project) && project.hasProperty("ossrhUsername")
} }
} }

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2016-2019 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
@@ -19,11 +19,17 @@ import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
/** /**
* Deploys the Spring XML schema (XSD) files to the spring.io server.
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
*/ */
class SchemaDeployPlugin implements Plugin<Project> { class SchemaDeployPlugin implements Plugin<Project> {
static final String DEFAULT_SPRING_DOCS_HOST = 'docs-ip.spring.io';
@Override @Override
void apply(Project project) { void apply(Project project) {
@@ -42,7 +48,7 @@ class SchemaDeployPlugin implements Plugin<Project> {
host = project.hasProperty('deployDocsHost') host = project.hasProperty('deployDocsHost')
? project.findProperty('deployDocsHost') ? project.findProperty('deployDocsHost')
: 'docs.af.pivotal.io' : DEFAULT_SPRING_DOCS_HOST
user = project.findProperty('deployDocsSshUsername') user = project.findProperty('deployDocsSshUsername')
@@ -50,11 +56,11 @@ class SchemaDeployPlugin implements Plugin<Project> {
? project.file(project.findProperty('deployDocsSshKeyPath')) ? project.file(project.findProperty('deployDocsSshKeyPath'))
: project.hasProperty('deployDocsSshKey') : project.hasProperty('deployDocsSshKey')
? project.findProperty('deployDocsSshKey') ? project.findProperty('deployDocsSshKey')
: identity : null
passphrase = project.hasProperty('deployDocsSshPassphrase') passphrase = project.hasProperty('deployDocsSshPassphrase')
? project.findProperty('deployDocsSshPassphrase') ? project.findProperty('deployDocsSshPassphrase')
: passphrase : null
} }
} }
@@ -71,9 +77,9 @@ class SchemaDeployPlugin implements Plugin<Project> {
execute "mkdir -p $tempPath" execute "mkdir -p $tempPath"
project.tasks.schemaZip.outputs.each { o -> project.tasks.schemaZip.outputs.each { out ->
println "Putting $o.files" println "Putting $out.files"
put from: o.files, into: tempPath put from: out.files, into: tempPath
} }
execute "unzip $tempPath*.zip -d $tempPath" execute "unzip $tempPath*.zip -d $tempPath"

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2016-2019 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
@@ -19,14 +19,18 @@ import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
/** /**
* Gradle {@link Plugin} to ZIP and deploy Spring XML schemas (XSDK) files.
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
*/ */
class SchemaPlugin implements Plugin<Project> { class SchemaPlugin implements Plugin<Project> {
@Override @Override
void apply(Project project) { void apply(Project project) {
project.getPluginManager().apply(SchemaDeployPlugin)
project.getPluginManager().apply(SchemaZipPlugin) project.getPluginManager().apply(SchemaZipPlugin)
project.getPluginManager().apply(SchemaDeployPlugin)
} }
} }

View File

@@ -1,28 +1,33 @@
/* /*
* Copyright 2016-2019 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.bundling.Zip import org.gradle.api.tasks.bundling.Zip
/** /**
* Zips all Spring XML schemas (XSD) files.
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
*/ */
class SchemaZipPlugin implements Plugin<Project> { class SchemaZipPlugin implements Plugin<Project> {
@@ -33,8 +38,8 @@ class SchemaZipPlugin implements Plugin<Project> {
schemaZip.archiveBaseName = project.rootProject.name schemaZip.archiveBaseName = project.rootProject.name
schemaZip.archiveClassifier = 'schema' schemaZip.archiveClassifier = 'schema'
schemaZip.description = "Builds -${schemaZip.archiveClassifier} archive containing all " + schemaZip.description = "Builds -${schemaZip.archiveClassifier} archive containing all XSDs" +
"XSDs for deployment at static.springframework.org/schema." " for deployment to static.springframework.org/schema."
schemaZip.group = 'Distribution' schemaZip.group = 'Distribution'
project.rootProject.subprojects.each { module -> project.rootProject.subprojects.each { module ->
@@ -49,9 +54,9 @@ class SchemaZipPlugin implements Plugin<Project> {
for (def key : schemas.keySet()) { for (def key : schemas.keySet()) {
def shortName = key.replaceAll(/http.*schema.(.*).spring-.*/, '$1') def zipEntryName = key.replaceAll(/http.*schema.(.*).spring-.*/, '$1')
assert shortName != key assert zipEntryName != key
File xsdFile = module.sourceSets.main.resources.find { File xsdFile = module.sourceSets.main.resources.find {
it.path.endsWith(schemas.get(key)) it.path.endsWith(schemas.get(key))
@@ -59,8 +64,8 @@ class SchemaZipPlugin implements Plugin<Project> {
assert xsdFile != null assert xsdFile != null
schemaZip.into (shortName) { schemaZip.into(zipEntryName) {
duplicatesStrategy 'exclude' duplicatesStrategy DuplicatesStrategy.EXCLUDE
from xsdFile.path from xsdFile.path
} }
} }

View File

@@ -1,60 +0,0 @@
/*
* 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 io.spring.gradle.dependencymanagement.DependencyManagementPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
/**
* Adds and configures {@link DependencyManagementPlugin}.
* <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> {
static final String DEPENDENCY_MANAGEMENT_RESOURCE = "gradle/dependency-management.gradle"
@Override
void apply(Project project) {
project.getPluginManager().apply(ManagementConfigurationPlugin)
project.getPluginManager().apply(DependencyManagementPlugin)
project.dependencyManagement {
resolutionStrategy {
cacheChangingModulesFor 0, "seconds"
}
}
File rootDir = project.rootDir
List<File> dependencyManagementFiles = [project.rootProject.file(DEPENDENCY_MANAGEMENT_RESOURCE)]
for (File dir = project.projectDir; dir != rootDir; dir = dir.parentFile) {
dependencyManagementFiles.add(new File(dir, DEPENDENCY_MANAGEMENT_RESOURCE))
}
dependencyManagementFiles.each { f ->
if (f.exists()) {
project.apply from: f.absolutePath
}
}
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright 2022-present 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.dependencymanagement.DependencyManagementPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
/**
* Applies and configures the Spring Gradle {@link DependencyManagementPlugin}.
*
* Additionally, if a {@literal gradle/dependency-management.gradle} file is present in a Gradle {@link Project},
* then this file will be automatically applied in order to configure {@link Project} additional dependencies.
*
* @author Rob Winch
* @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
* @see org.gradle.api.plugins.PluginManager
*/
class SpringDependencyManagementConventionsPlugin implements Plugin<Project> {
static final String DEPENDENCY_MANAGEMENT_RESOURCE = "gradle/dependency-management.gradle"
@Override
void apply(Project project) {
applyAndConfigureDependencyManagementPlugin(project)
applyDependencyManagementResources(project)
}
private void applyAndConfigureDependencyManagementPlugin(Project project) {
project.getPluginManager().apply(DependencyManagementPlugin)
project.dependencyManagement {
resolutionStrategy {
cacheChangingModulesFor 0, "seconds"
}
}
}
@SuppressWarnings("all")
private void applyDependencyManagementResources(Project project) {
File rootDir = project.rootDir
List<File> dependencyManagementFiles = [ project.rootProject.file(DEPENDENCY_MANAGEMENT_RESOURCE) ]
for (File dir = project.projectDir; dir != rootDir; dir = dir.parentFile) {
dependencyManagementFiles.add(new File(dir, DEPENDENCY_MANAGEMENT_RESOURCE))
}
dependencyManagementFiles.each { file ->
if (file.exists()) {
project.apply from: file.absolutePath
}
}
}
}

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2016-2019 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
@@ -21,29 +21,23 @@ import org.gradle.api.plugins.PluginManager
import org.springframework.gradle.maven.SpringMavenPlugin import org.springframework.gradle.maven.SpringMavenPlugin
/** /**
* Defines the Gradle project as a proper Spring Module. * Defines a Gradle {@link Project} as a Spring module.
* *
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see io.spring.gradle.convention.AbstractSpringJavaPlugin
* @see org.springframework.gradle.maven.SpringMavenPlugin
* @see org.gradle.api.plugins.JavaLibraryPlugin
* @see org.gradle.api.Project
*/ */
class SpringModulePlugin extends AbstractSpringJavaPlugin { class SpringModulePlugin extends AbstractSpringJavaPlugin {
@Override @Override
void additionalPlugins(Project project) { void applyAdditionalPlugins(Project project) {
PluginManager pluginManager = project.getPluginManager(); PluginManager pluginManager = project.getPluginManager();
pluginManager.apply(JavaLibraryPlugin.class) pluginManager.apply(JavaLibraryPlugin.class)
pluginManager.apply(SpringMavenPlugin.class); pluginManager.apply(SpringMavenPlugin.class);
pluginManager.apply("io.spring.convention.jacoco");
def deployArtifacts = project.task("deployArtifacts")
deployArtifacts.group = 'Deploy tasks'
deployArtifacts.description = "Deploys the artifacts to either Artifactory or Maven Central"
if (!Utils.isRelease(project)) {
deployArtifacts.dependsOn project.tasks.artifactoryPublish
}
} }
} }

View File

@@ -1,22 +1,21 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.plugins.PluginManager
/** /**
* @author Rob Winch * @author Rob Winch
@@ -25,17 +24,15 @@ import org.gradle.api.plugins.PluginManager
class SpringSampleBootPlugin extends SpringSamplePlugin { class SpringSampleBootPlugin extends SpringSamplePlugin {
@Override @Override
void additionalPlugins(Project project) { void applyAdditionalPlugins(Project project) {
super.additionalPlugins(project); project.getPluginManager().apply("org.springframework.boot");
PluginManager pluginManager = project.getPluginManager(); super.applyAdditionalPlugins(project);
pluginManager.apply("org.springframework.boot");
project.repositories { project.repositories {
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' } maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
} }
} }
} }

View File

@@ -1,33 +1,34 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention; package io.spring.gradle.convention
import org.gradle.api.Project import org.gradle.api.Project
import org.sonarqube.gradle.SonarQubePlugin;
/** /**
* Gradle Spring Java Plugin used to identify a Gradle {@link Project} as a {@literal Sample} and add configuration
* to skip Sonar Qube inspections.
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Project
*/ */
class SpringSamplePlugin extends AbstractSpringJavaPlugin { class SpringSamplePlugin extends AbstractSpringJavaPlugin {
@Override @Override
void additionalPlugins(Project project) { void applyAdditionalPlugins(Project project) {
project.plugins.withType(SonarQubePlugin) { Utils.skipProjectWithSonarQubePlugin(project)
project.sonarqube.skipProject = true
}
} }
} }

View File

@@ -1,53 +1,71 @@
/* /*
* Copyright 2016-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention package io.spring.gradle.convention
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.Task import org.gradle.api.Task
import org.gradle.api.plugins.PluginManager import org.gradle.api.plugins.PluginManager
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.testing.Test import org.gradle.api.tasks.testing.Test
/** /**
* Spring Sample Gradle Plugin used to build Samples as a Java Web Application (WAR archive).
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Project
* @see org.gradle.api.Task
*/ */
class SpringSampleWarPlugin extends SpringSamplePlugin { class SpringSampleWarPlugin extends SpringSamplePlugin {
@Override @Override
void additionalPlugins(Project project) { void applyAdditionalPlugins(Project project) {
super.additionalPlugins(project); super.applyAdditionalPlugins(project)
PluginManager pluginManager = project.getPluginManager(); PluginManager pluginManager = project.getPluginManager()
pluginManager.apply("war"); pluginManager.apply("war")
pluginManager.apply("org.gretty"); pluginManager.apply("org.gretty")
def resolvedLogbackConfigFile = new File(project.extensions.getByType(SourceSetContainer)
.findByName("integrationTest")?.resources?.filter {
"logback-test.xml".equals(it.name)
}?.singleFile?.absolutePath)
// println "Resolved logbackConfigFile [$resolvedLogbackConfigFile]"
project.gretty { project.gretty {
servletContainer = 'tomcat10' servletContainer = 'tomcat10'
contextPath = '/' contextPath = '/'
consoleLogEnabled = false
fileLogEnabled = false fileLogEnabled = false
loggingLevel = 'OFF'
if (resolvedLogbackConfigFile?.isFile()) {
logbackConfigFile = resolvedLogbackConfigFile
}
} }
Task prepareAppServerForIntegrationTests = project.tasks.create('prepareAppServerForIntegrationTests') { Task prepareAppServerForIntegrationTests = project.tasks.create('prepareAppServerForIntegrationTests') {
group = 'Verification' group = 'Verification'
description = 'Prepares the app server for integration tests' description = 'Prepares the Web application server for Integration Testing'
doFirst { doFirst {
project.gretty { project.gretty {
httpPort = getRandomFreePort() httpPort = getRandomPort()
httpsPort = getRandomPort() httpsPort = getRandomPort()
} }
} }
@@ -58,13 +76,13 @@ class SpringSampleWarPlugin extends SpringSamplePlugin {
} }
project.tasks.withType(Test).all { task -> project.tasks.withType(Test).all { task ->
if("integrationTest".equals(task.name)) { if ("integrationTest".equals(task.name)) {
applyForIntegrationTest(project, task) applyForIntegrationTest(project, task)
} }
} }
} }
def applyForIntegrationTest(Project project, Task integrationTest) { def static applyForIntegrationTest(Project project, Task integrationTest) {
project.gretty.integrationTestTask = integrationTest.name project.gretty.integrationTestTask = integrationTest.name
@@ -79,8 +97,8 @@ class SpringSampleWarPlugin extends SpringSamplePlugin {
int port = isHttps ? httpsPort : httpPort int port = isHttps ? httpsPort : httpPort
String host = project.gretty.host ?: 'localhost' String host = gretty.host ?: 'localhost'
String contextPath = project.gretty.contextPath String contextPath = gretty.contextPath
String httpBaseUrl = "http://${host}:${httpPort}${contextPath}" String httpBaseUrl = "http://${host}:${httpPort}${contextPath}"
String httpsBaseUrl = "https://${host}:${httpsPort}${contextPath}" String httpsBaseUrl = "https://${host}:${httpsPort}${contextPath}"
String baseUrl = isHttps ? httpsBaseUrl : httpBaseUrl String baseUrl = isHttps ? httpsBaseUrl : httpBaseUrl
@@ -96,7 +114,7 @@ class SpringSampleWarPlugin extends SpringSamplePlugin {
} }
} }
def getRandomPort() { def static getRandomPort() {
ServerSocket serverSocket = new ServerSocket(0) ServerSocket serverSocket = new ServerSocket(0)
int port = serverSocket.localPort int port = serverSocket.localPort
serverSocket.close() serverSocket.close()

View File

@@ -1,30 +1,31 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention; package io.spring.gradle.convention
import org.gradle.api.Project; import org.gradle.api.Project
/** /**
* Gradle Plugin used to disable Sonar Qube inspection(s) during Spring project tests.
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
*/ */
class SpringTestPlugin extends AbstractSpringJavaPlugin { class SpringTestPlugin extends AbstractSpringJavaPlugin {
@Override @Override
void additionalPlugins(Project project) { void applyAdditionalPlugins(Project project) {
project.sonarqube.skipProject = true Utils.skipProjectWithSonarQubePlugin(project)
} }
} }

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention; package io.spring.gradle.convention;
@@ -21,7 +21,7 @@ import org.gradle.api.plugins.JavaPlugin
import org.gradle.jvm.tasks.Jar import org.gradle.jvm.tasks.Jar
/** /**
* Adds the ability to depends on the test jar within other projects using: * Adds ability to depend on the test JAR within other Gradle {@link Project Projects} using:
* *
* <code> * <code>
* testImplementation project(path: ':foo', configuration: 'tests') * testImplementation project(path: ':foo', configuration: 'tests')
@@ -29,29 +29,28 @@ import org.gradle.jvm.tasks.Jar
* *
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
*/ */
class TestsConfigurationPlugin implements Plugin<Project> { class TestsConfigurationPlugin implements Plugin<Project> {
@Override @Override
void apply(Project project) { void apply(Project project) {
project.plugins.withType(JavaPlugin) { project.plugins.withType(JavaPlugin) {
applyJavaProject(project)
}
}
private void applyJavaProject(Project project) { project.configurations {
tests.extendsFrom testRuntimeClasspath
}
project.configurations { project.tasks.create('testJar', Jar) {
tests.extendsFrom testRuntime, testRuntimeClasspath archiveClassifier = 'test'
} from project.sourceSets.test.output
}
project.tasks.create('testJar', Jar) { project.artifacts {
classifier = 'test' tests project.testJar
from project.sourceSets.test.output }
}
project.artifacts {
tests project.testJar
} }
} }
} }

View File

@@ -1,25 +1,29 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package io.spring.gradle.convention; package io.spring.gradle.convention
import org.gradle.api.Project; import org.gradle.api.Project
import org.sonarqube.gradle.SonarQubePlugin
/** /**
* Utility class encapsulating common operations on Gradle {@link Project Projects}.
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Project
*/ */
class Utils { class Utils {
@@ -27,13 +31,13 @@ class Utils {
static String getProjectName(Project project) { static String getProjectName(Project project) {
String projectName = project.getRootProject().getName(); String projectName = project.getRootProject().getName()
if(projectName.endsWith("-build")) { if (projectName.endsWith("-build")) {
projectName = projectName.substring(0, projectName.length() - "-build".length()); projectName = projectName.substring(0, projectName.length() - "-build".length())
} }
return projectName; return projectName
} }
static boolean isMilestone(Project project) { static boolean isMilestone(Project project) {
@@ -50,6 +54,17 @@ class Utils {
} }
private static String projectVersion(Project project) { private static String projectVersion(Project project) {
return String.valueOf(project.getVersion()); return String.valueOf(project.version)
}
static String findPropertyAsString(Project project, String propertyName) {
return (String) project.findProperty(propertyName)
}
static void skipProjectWithSonarQubePlugin(Project project) {
project.plugins.withType(SonarQubePlugin) {
project.sonarqube.skipProject = true
}
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2019-2020 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import org.gradle.api.Plugin;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.dsl.RepositoryHandler; import org.gradle.api.artifacts.dsl.RepositoryHandler;
import org.gradle.api.file.DuplicatesStrategy;
import org.gradle.api.file.FileTree; import org.gradle.api.file.FileTree;
import org.gradle.api.tasks.Sync; import org.gradle.api.tasks.Sync;
@@ -65,6 +66,16 @@ import org.gradle.api.tasks.Sync;
*/ */
public class AsciidoctorConventionPlugin implements Plugin<Project> { public class AsciidoctorConventionPlugin implements Plugin<Project> {
private static final String SPRING_ASCIIDOCTOR_EXTENSIONS_BLOCK_SWITCH_VERSION = "0.4.2.RELEASE";
private static final String SPRING_DOC_RESOURCES_VERSION = "0.2.5";
private static final String SPRING_ASCIIDOCTOR_EXTENSION_BLOCK_SWITCH_DEPENDENCY =
String.format("io.spring.asciidoctor:spring-asciidoctor-extensions-block-switch:%s",
SPRING_ASCIIDOCTOR_EXTENSIONS_BLOCK_SWITCH_VERSION);
private static final String SPRING_DOC_RESOURCES_DEPENDENCY =
String.format("io.spring.docresources:spring-doc-resources:%s", SPRING_DOC_RESOURCES_VERSION);
@Override @Override
public void apply(Project project) { public void apply(Project project) {
@@ -78,13 +89,14 @@ public class AsciidoctorConventionPlugin implements Plugin<Project> {
project.getTasks().withType(AbstractAsciidoctorTask.class, asciidoctorTask -> { project.getTasks().withType(AbstractAsciidoctorTask.class, asciidoctorTask -> {
asciidoctorTask.dependsOn(unzipResources); asciidoctorTask.dependsOn(unzipResources);
configureAttributes(project, asciidoctorTask);
configureExtensions(project, asciidoctorTask); configureExtensions(project, asciidoctorTask);
configureCommonAttributes(project, asciidoctorTask);
configureOptions(asciidoctorTask); configureOptions(asciidoctorTask);
asciidoctorTask.baseDirFollowsSourceDir(); asciidoctorTask.baseDirFollowsSourceDir();
asciidoctorTask.useIntermediateWorkDir(); asciidoctorTask.useIntermediateWorkDir();
asciidoctorTask.resources(resourcesSpec -> { asciidoctorTask.resources(resourcesSpec -> {
resourcesSpec.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE);
resourcesSpec.from(unzipResources); resourcesSpec.from(unzipResources);
resourcesSpec.from(asciidoctorTask.getSourceDir(), resourcesSrcDirSpec -> { resourcesSpec.from(asciidoctorTask.getSourceDir(), resourcesSrcDirSpec -> {
// https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/523 // https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/523
@@ -114,23 +126,36 @@ public class AsciidoctorConventionPlugin implements Plugin<Project> {
}); });
} }
/**
* Requests the base Spring Documentation Resources from {@literal https://repo.spring.io/release} and uses it
* to format and render documentation.
*
* @param project {@literal this} Gradle {@link Project}.
* @return a {@link Sync} task used to copy the Spring Documentation Resources to a build directory
* used to generate documentation.
* @see <a href="https://repo.spring.io/ui/native/release/io/spring/docresources/spring-doc-resources">spring-doc-resources</a>
* @see org.gradle.api.tasks.Sync
* @see org.gradle.api.Project
*/
@SuppressWarnings("all") @SuppressWarnings("all")
private Sync createUnzipDocumentationResourcesTask(Project project) { private Sync createUnzipDocumentationResourcesTask(Project project) {
Configuration documentationResources = project.getConfigurations().maybeCreate("documentationResources"); Configuration documentationResources = project.getConfigurations().maybeCreate("documentationResources");
documentationResources.getDependencies() documentationResources.getDependencies()
.add(project.getDependencies().create("io.spring.docresources:spring-doc-resources:0.2.5")); .add(project.getDependencies().create(SPRING_DOC_RESOURCES_DEPENDENCY));
Sync unzipResources = project.getTasks().create("unzipDocumentationResources", Sync.class, sync -> { Sync unzipResources = project.getTasks().create("unzipDocumentationResources", Sync.class, sync -> {
sync.dependsOn(documentationResources); sync.dependsOn(documentationResources);
sync.from((Callable<List<FileTree>>) () -> { Callable<List<FileTree>> source = () -> {
List<FileTree> result = new ArrayList<>(); List<FileTree> result = new ArrayList<>();
documentationResources.getAsFileTree().forEach(file -> result.add(project.zipTree(file))); documentationResources.getAsFileTree().forEach(file -> result.add(project.zipTree(file)));
return result; return result;
}); };
sync.from(source);
File destination = new File(project.getBuildDir(), "docs/resources"); File destination = new File(project.getBuildDir(), "docs/resources");
@@ -141,7 +166,8 @@ public class AsciidoctorConventionPlugin implements Plugin<Project> {
return unzipResources; return unzipResources;
} }
private void configureCommonAttributes(Project project, AbstractAsciidoctorTask asciidoctorTask) { @SuppressWarnings("unused")
private void configureAttributes(Project project, AbstractAsciidoctorTask asciidoctorTask) {
Map<String, Object> attributes = new HashMap<>(); Map<String, Object> attributes = new HashMap<>();
@@ -157,6 +183,16 @@ public class AsciidoctorConventionPlugin implements Plugin<Project> {
asciidoctorTask.attributes(attributes); asciidoctorTask.attributes(attributes);
} }
private void configureExtensions(Project project, AbstractAsciidoctorTask asciidoctorTask) {
Configuration extensionsConfiguration = project.getConfigurations().maybeCreate("asciidoctorExtensions");
extensionsConfiguration.defaultDependencies(dependencies -> dependencies.add(project.getDependencies()
.create(SPRING_ASCIIDOCTOR_EXTENSION_BLOCK_SWITCH_DEPENDENCY)));
asciidoctorTask.configurations(extensionsConfiguration);
}
private void configureHtmlOnlyAttributes(Project project, AbstractAsciidoctorTask asciidoctorTask) { private void configureHtmlOnlyAttributes(Project project, AbstractAsciidoctorTask asciidoctorTask) {
Map<String, Object> attributes = new HashMap<>(); Map<String, Object> attributes = new HashMap<>();
@@ -184,16 +220,6 @@ public class AsciidoctorConventionPlugin implements Plugin<Project> {
asciidoctorTask.attributes(attributes); asciidoctorTask.attributes(attributes);
} }
private void configureExtensions(Project project, AbstractAsciidoctorTask asciidoctorTask) {
Configuration extensionsConfiguration = project.getConfigurations().maybeCreate("asciidoctorExtensions");
extensionsConfiguration.defaultDependencies(dependencies -> dependencies.add(project.getDependencies()
.create("io.spring.asciidoctor:spring-asciidoctor-extensions-block-switch:0.4.2.RELEASE")));
asciidoctorTask.configurations(extensionsConfiguration);
}
private void configureOptions(AbstractAsciidoctorTask asciidoctorTask) { private void configureOptions(AbstractAsciidoctorTask asciidoctorTask) {
asciidoctorTask.options(Collections.singletonMap("doctype", "book")); asciidoctorTask.options(Collections.singletonMap("doctype", "book"));
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,26 +13,36 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.gradle; package org.springframework.gradle;
import org.gradle.api.Plugin; import org.gradle.api.Plugin;
import org.gradle.api.Project; import org.gradle.api.Project;
/**
* Copies {@literal root} {@link Project} properties to the target ({@literal this}) {@link Project},
* the {@link Project} for which {@literal this} Gradle {@link Plugin} is applied.
*
* @author Rob Winch
* @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
*/
public class CopyPropertiesPlugin implements Plugin<Project> { public class CopyPropertiesPlugin implements Plugin<Project> {
@Override @Override
public void apply(Project project) { public void apply(Project project) {
copyPropertyFromRootProjectTo("group", project); copyPropertyFromRootProjectTo("group", project);
copyPropertyFromRootProjectTo("version", project); copyPropertyFromRootProjectTo("version", project);
copyPropertyFromRootProjectTo("description", project); copyPropertyFromRootProjectTo("description", project);
} }
private void copyPropertyFromRootProjectTo(String propertyName, Project project) { private void copyPropertyFromRootProjectTo(String propertyName, Project project) {
Project rootProject = project.getRootProject();
Object property = rootProject.findProperty(propertyName); Object propertyValue = project.getRootProject().findProperty(propertyName);
if(property != null) {
project.setProperty(propertyName, property); if (propertyValue != null) {
project.setProperty(propertyName, propertyValue);
} }
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2019-2020 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2019-2020 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2019-2020 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2022-present 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.github.milestones; package org.springframework.gradle.github.milestones;
public class Milestone { public class Milestone {

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2022-present 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.github.milestones; package org.springframework.gradle.github.milestones;
public class RepositoryRef { public class RepositoryRef {
private String owner; private String owner;

View File

@@ -1,22 +1,20 @@
/* /*
* Copyright 2016-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package org.springframework.gradle.maven; package org.springframework.gradle.maven;
import org.gradle.api.Action;
import org.gradle.api.Plugin; import org.gradle.api.Plugin;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPlugin;
@@ -31,68 +29,91 @@ import org.gradle.api.publish.maven.MavenPomScm;
import org.gradle.api.publish.maven.MavenPublication; import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin; import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
public class MavenPublishingConventionsPlugin implements Plugin<Project> { /**
* Customizes the Maven POM generated from the Gradle {@link Project}.
*
* @author Rob Winch
* @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
* @see org.gradle.api.publish.PublishingExtension
* @see org.gradle.api.publish.maven.MavenPom
* @see org.gradle.api.publish.maven.MavenPublication
* @see org.gradle.api.publish.maven.plugins.MavenPublishPlugin
*/
public class MavenPublishConventionsPlugin implements Plugin<Project> {
@Override @Override
public void apply(Project project) { public void apply(Project project) {
project.getPlugins().withType(MavenPublishPlugin.class).all(new Action<MavenPublishPlugin>() {
@Override project.getPlugins().withType(MavenPublishPlugin.class).all(mavenPublishPlugin -> {
public void execute(MavenPublishPlugin mavenPublish) {
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class); customizeJavaPlugin(project);
publishing.getPublications().withType(MavenPublication.class)
.all((mavenPublication) -> MavenPublishingConventionsPlugin.this.customizePom(mavenPublication.getPom(), project)); PublishingExtension publishingExtension = project.getExtensions().getByType(PublishingExtension.class);
MavenPublishingConventionsPlugin.this.customizeJavaPlugin(project);
} publishingExtension.getPublications().withType(MavenPublication.class).all(mavenPublication ->
customizeMavenPom(project, mavenPublication.getPom()));
}); });
} }
private void customizePom(MavenPom pom, Project project) { private void customizeJavaPlugin(Project project) {
pom.getUrl().set("https://spring.io/projects/spring-session");
project.getPlugins().withType(JavaPlugin.class).all(javaPlugin -> {
JavaPluginExtension extension = project.getExtensions().getByType(JavaPluginExtension.class);
extension.withJavadocJar();
extension.withSourcesJar();
});
}
private void customizeMavenPom(Project project, MavenPom pom) {
pom.getName().set(project.provider(project::getName)); pom.getName().set(project.provider(project::getName));
pom.getDescription().set(project.provider(project::getDescription)); pom.getDescription().set(project.provider(project::getDescription));
pom.organization(this::customizeOrganization); pom.getUrl().set("https://github.com/spring-projects/spring-test-data-geode");
pom.licenses(this::customizeLicences); pom.licenses(this::customizeLicences);
pom.organization(this::customizeOrganization);
pom.developers(this::customizeDevelopers); pom.developers(this::customizeDevelopers);
pom.scm(this::customizeScm); pom.scm(this::customizeScm);
pom.issueManagement(this::customizeIssueManagement); pom.issueManagement(this::customizeIssueManagement);
} }
private void customizeOrganization(MavenPomOrganization organization) { private void customizeDevelopers(MavenPomDeveloperSpec developers) {
organization.getName().set("Pivotal Software, Inc.");
organization.getUrl().set("https://spring.io"); developers.developer(developer -> {
developer.getName().set("VMware");
developer.getEmail().set("info@vmware.com");
developer.getOrganization().set("VMware, Inc.");
developer.getOrganizationUrl().set("https://www.spring.io");
});
}
private void customizeIssueManagement(MavenPomIssueManagement issueManagement) {
issueManagement.getSystem().set("GitHub");
issueManagement.getUrl().set("https://github.com/spring-projects/spring-test-data-geode/issues");
} }
private void customizeLicences(MavenPomLicenseSpec licences) { private void customizeLicences(MavenPomLicenseSpec licences) {
licences.license((licence) -> {
licences.license(licence -> {
licence.getName().set("Apache License, Version 2.0"); licence.getName().set("Apache License, Version 2.0");
licence.getUrl().set("https://www.apache.org/licenses/LICENSE-2.0"); licence.getUrl().set("https://www.apache.org/licenses/LICENSE-2.0");
}); });
} }
private void customizeDevelopers(MavenPomDeveloperSpec developers) { private void customizeOrganization(MavenPomOrganization organization) {
developers.developer((developer) -> {
developer.getName().set("Pivotal"); organization.getName().set("VMware, Inc.");
developer.getEmail().set("info@pivotal.io"); organization.getUrl().set("https://spring.io");
developer.getOrganization().set("Pivotal Software, Inc.");
developer.getOrganizationUrl().set("https://www.spring.io");
});
} }
private void customizeScm(MavenPomScm scm) { private void customizeScm(MavenPomScm scm) {
scm.getConnection().set("scm:git:git://github.com/spring-projects/spring-session.git");
scm.getDeveloperConnection().set("scm:git:ssh://git@github.com/spring-projects/spring-session.git");
scm.getUrl().set("https://github.com/spring-projects/spring-session");
}
private void customizeIssueManagement(MavenPomIssueManagement issueManagement) { scm.getConnection().set("scm:git:git://github.com/spring-projects/spring-test-data-geode.git");
issueManagement.getSystem().set("GitHub"); scm.getDeveloperConnection().set("scm:git:ssh://git@github.com/spring-projects/spring-test-data-geode.git");
issueManagement.getUrl().set("https://github.com/spring-projects/spring-session/issues"); scm.getUrl().set("https://github.com/spring-projects/spring-test-data-geode");
}
private void customizeJavaPlugin(Project project) {
project.getPlugins().withType(JavaPlugin.class).all((javaPlugin) -> {
JavaPluginExtension extension = project.getExtensions().getByType(JavaPluginExtension.class);
extension.withJavadocJar();
extension.withSourcesJar();
});
} }
} }

View File

@@ -1,32 +1,60 @@
/*
* Copyright 2022-present 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; package org.springframework.gradle.maven;
import org.gradle.api.Action;
import org.gradle.api.Plugin; import org.gradle.api.Plugin;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlatformPlugin; import org.gradle.api.plugins.JavaPlatformPlugin;
import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.publish.PublishingExtension; import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.VariantVersionMappingStrategy;
import org.gradle.api.publish.VersionMappingStrategy;
import org.gradle.api.publish.maven.MavenPublication; import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin; import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
/**
* Adds Java and JavaPlatform based Gradle {@link Project Pojects} to be published by Maven.
*
* @author Rob Winch
* @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
* @see org.gradle.api.plugins.JavaPlatformPlugin
* @see org.gradle.api.plugins.JavaPlugin
* @see org.gradle.api.publish.PublishingExtension
* @see org.gradle.api.publish.maven.MavenPublication
* @see org.gradle.api.publish.maven.plugins.MavenPublishPlugin
*/
public class PublishAllJavaComponentsPlugin implements Plugin<Project> { public class PublishAllJavaComponentsPlugin implements Plugin<Project> {
private static final String JAVA_COMPONENT_NAME = "java";
private static final String JAVA_PLATFORM_COMPONENT_NAME = "javaPlatform";
@Override @Override
public void apply(Project project) { public void apply(Project project) {
project.getPlugins().withType(MavenPublishPlugin.class).all((mavenPublish) -> {
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class); project.getPlugins().withType(MavenPublishPlugin.class).all(mavenPublish -> {
publishing.getPublications().create("mavenJava", MavenPublication.class, new Action<MavenPublication>() {
@Override PublishingExtension publishingExtension = project.getExtensions().getByType(PublishingExtension.class);
public void execute(MavenPublication maven) {
project.getPlugins().withType(JavaPlugin.class, (plugin) -> { publishingExtension.getPublications().create("mavenJava", MavenPublication.class, mavenPublication -> {
maven.from(project.getComponents().getByName("java"));
}); project.getPlugins().withType(JavaPlugin.class, javaPlugin ->
project.getPlugins().withType(JavaPlatformPlugin.class, (plugin) -> { mavenPublication.from(project.getComponents().getByName(JAVA_COMPONENT_NAME)));
maven.from(project.getComponents().getByName("javaPlatform"));
}); project.getPlugins().withType(JavaPlatformPlugin.class, javaPlatformPlugin ->
} mavenPublication.from(project.getComponents().getByName(JAVA_PLATFORM_COMPONENT_NAME)));
}); });
}); });
} }

View File

@@ -1,25 +1,51 @@
/*
* Copyright 2022-present 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; package org.springframework.gradle.maven;
import io.spring.gradle.convention.Utils;
import org.gradle.api.Action;
import org.gradle.api.Plugin; import org.gradle.api.Plugin;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.Task;
import io.spring.gradle.convention.Utils;
/**
* Publishes Gradle {@link Project} artifacts to either Artifactory or Maven Central.
*
* @author Rob Winch
* @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
* @see <a href="https://www.jfrog.com/confluence/display/JFROG/Gradle+Artifactory+Plugin">Artifatory Gradle Plugin</a>
* @see <a href="https://central.sonatype.org/publish/publish-gradle/">Maven Central Sonatype Gradle Support</a>
*/
public class PublishArtifactsPlugin implements Plugin<Project> { public class PublishArtifactsPlugin implements Plugin<Project> {
@Override @Override
public void apply(Project project) { public void apply(Project project) {
project.getTasks().register("publishArtifacts", new Action<Task>() {
@Override project.getTasks().register("publishArtifacts", publishArtifactsTask -> {
public void execute(Task publishArtifacts) {
publishArtifacts.setGroup("Publishing"); publishArtifactsTask.setGroup("Publishing");
publishArtifacts.setDescription("Publish the artifacts to either Artifactory or Maven Central based on the version"); publishArtifactsTask.setDescription("Publish project artifacts to either Artifactory or Maven Central"
if (Utils.isRelease(project)) { + " based on the project version.");
publishArtifacts.dependsOn("publishToOssrh");
} if (Utils.isRelease(project)) {
else { publishArtifactsTask.dependsOn("publishToOssrh");
publishArtifacts.dependsOn("artifactoryPublish"); }
} else {
publishArtifactsTask.dependsOn("artifactoryPublish");
} }
}); });
} }

View File

@@ -1,29 +1,53 @@
/*
* Copyright 2022-present 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; package org.springframework.gradle.maven;
import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
import java.io.File; import java.io.File;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
/**
* Gradle Plugin used to publish all {@link Project} artifacts locally
* under {@literal rootProject/buildDir/publications/repos}.
*
* This is useful for inspecting the generated {@link Project} artifacts to ensure they are correct
* before publishing the {@link Project} artifacts to Artifactory or Maven Central.
*
* @author Rob Winch
* @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
* @since 2.0.0
*/
public class PublishLocalPlugin implements Plugin<Project> { public class PublishLocalPlugin implements Plugin<Project> {
@Override @Override
public void apply(Project project) { public void apply(Project project) {
project.getPlugins().withType(MavenPublishPlugin.class).all(new Action<MavenPublishPlugin>() {
@Override project.getPlugins().withType(MavenPublishPlugin.class).all(mavenPublish -> {
public void execute(MavenPublishPlugin mavenPublish) {
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class); PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
publishing.getRepositories().maven(new Action<MavenArtifactRepository>() {
@Override publishing.getRepositories().maven(maven -> {
public void execute(MavenArtifactRepository maven) { maven.setName("local");
maven.setName("local"); maven.setUrl(new File(project.getRootProject().getBuildDir(), "publications/repos"));
maven.setUrl(new File(project.getRootProject().getBuildDir(), "publications/repos")); });
}
});
}
}); });
} }
} }

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package org.springframework.gradle.maven; package org.springframework.gradle.maven;
@@ -22,8 +22,13 @@ import org.gradle.api.plugins.PluginManager;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin; import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
/** /**
* Enables publishing to Maven for a Spring module Gradle {@link Project}.
*
* @author Rob Winch * @author Rob Winch
* @author John Blum * @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
* @see org.gradle.api.publish.maven.plugins.MavenPublishPlugin
*/ */
public class SpringMavenPlugin implements Plugin<Project> { public class SpringMavenPlugin implements Plugin<Project> {
@@ -33,11 +38,11 @@ public class SpringMavenPlugin implements Plugin<Project> {
PluginManager pluginManager = project.getPluginManager(); PluginManager pluginManager = project.getPluginManager();
pluginManager.apply(MavenPublishPlugin.class); pluginManager.apply(MavenPublishPlugin.class);
pluginManager.apply(SpringSigningPlugin.class); pluginManager.apply(MavenPublishConventionsPlugin.class);
pluginManager.apply(MavenPublishingConventionsPlugin.class);
pluginManager.apply(PublishAllJavaComponentsPlugin.class); pluginManager.apply(PublishAllJavaComponentsPlugin.class);
pluginManager.apply(PublishLocalPlugin.class);
pluginManager.apply(PublishArtifactsPlugin.class); pluginManager.apply(PublishArtifactsPlugin.class);
pluginManager.apply(PublishLocalPlugin.class);
pluginManager.apply(SpringSigningPlugin.class);
pluginManager.apply(ArtifactoryPlugin.class); pluginManager.apply(ArtifactoryPlugin.class);
} }
} }

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package org.springframework.gradle.maven; package org.springframework.gradle.maven;
@@ -24,22 +24,38 @@ import org.gradle.api.Project;
import io.github.gradlenexus.publishplugin.NexusPublishExtension; import io.github.gradlenexus.publishplugin.NexusPublishExtension;
import io.github.gradlenexus.publishplugin.NexusPublishPlugin; import io.github.gradlenexus.publishplugin.NexusPublishPlugin;
/**
* Enables a Gradle {@link Project} to publish to Maven Central using Sonatype's Nexus Repository Manager.
*
* @author Rob Winch
* @author John Blum
* @see <a href="https://github.com/gradle-nexus/publish-plugin">Nexus Publish Gradle Plugin</a>
*/
public class SpringNexusPublishPlugin implements Plugin<Project> { public class SpringNexusPublishPlugin implements Plugin<Project> {
private static final String SONATYPE_NEXUS_URL = "https://s01.oss.sonatype.org/service/local/";
private static final String SONATYPE_SNAPSHOT_REPOSITORY_URL = "https://s01.oss.sonatype.org/content/repositories/snapshots/";
@Override @Override
public void apply(Project project) { public void apply(Project project) {
project.getPlugins().apply(NexusPublishPlugin.class); project.getPlugins().apply(NexusPublishPlugin.class);
NexusPublishExtension nexusPublishing = project.getExtensions().findByType(NexusPublishExtension.class); NexusPublishExtension nexusPublishExtension = project.getExtensions().findByType(NexusPublishExtension.class);
nexusPublishing.getRepositories().create("ossrh", nexusRepository -> { // TODO: Why did we not simply use/configure the 'sonatype' repository and instead add a repo ('ossrh')?
nexusRepository.getNexusUrl().set(URI.create("https://s01.oss.sonatype.org/service/local/")); // See here: https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh
nexusRepository.getSnapshotRepositoryUrl() // NOTE: Careful, the keyword 'ossrh' is referred to in names in the Spring Build Conventions Gradle Plugins,
.set(URI.create("https://s01.oss.sonatype.org/content/repositories/snapshots/")); // such as, but not limited to:
// * 'ossrhUsername'
// * 'publishToOssrh'
// * 'closeAndReleaseOssrhStagingRepository'
nexusPublishExtension.getRepositories().create("ossrh", nexusRepository -> {
nexusRepository.getNexusUrl().set(URI.create(SONATYPE_NEXUS_URL));
nexusRepository.getSnapshotRepositoryUrl().set(URI.create(SONATYPE_SNAPSHOT_REPOSITORY_URL));
}); });
nexusPublishing.getConnectTimeout().set(Duration.ofMinutes(3)); nexusPublishExtension.getClientTimeout().set(Duration.ofMinutes(3));
nexusPublishing.getClientTimeout().set(Duration.ofMinutes(3)); nexusPublishExtension.getConnectTimeout().set(Duration.ofMinutes(3));
} }
} }

View File

@@ -1,17 +1,17 @@
/* /*
* Copyright 2016-2019 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License");
* use this file except in compliance with the License. You may obtain a copy of * you may not use this file except in compliance with the License.
* the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS,
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* License for the specific language governing permissions and limitations under * See the License for the specific language governing permissions and
* the License. * limitations under the License.
*/ */
package org.springframework.gradle.maven; package org.springframework.gradle.maven;
@@ -24,34 +24,76 @@ import org.gradle.api.publish.PublishingExtension;
import org.gradle.plugins.signing.SigningExtension; import org.gradle.plugins.signing.SigningExtension;
import org.gradle.plugins.signing.SigningPlugin; import org.gradle.plugins.signing.SigningPlugin;
import io.spring.gradle.convention.Utils;
/**
* Signs all Gradle {@link Project} artifacts.
*
* @author Rob Winch
* @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
* @see org.gradle.plugins.signing.SigningPlugin
*/
public class SpringSigningPlugin implements Plugin<Project> { public class SpringSigningPlugin implements Plugin<Project> {
@Override @Override
public void apply(Project project) { public void apply(Project project) {
project.getPluginManager().apply(SigningPlugin.class); if (isSigningRequired(project)) {
project.getPluginManager().apply(SigningPlugin.class);
sign(project);
}
}
project.getPlugins().withType(SigningPlugin.class).all(signingPlugin -> { private boolean isSigningRequired(Project project) {
return isSigningKeyPresent(project) && isRelease(project);
}
boolean hasSigningKey = project.hasProperty("signing.keyId") private boolean isSigningKeyPresent(Project project) {
|| project.hasProperty("signingKey");
if (hasSigningKey) { return project.hasProperty("signing.keyId")
sign(project); || project.hasProperty("signingKeyId")
} || project.hasProperty("signingKey");
}); }
private boolean isRelease(Project project) {
return Utils.isRelease(project);
} }
private void sign(Project project) { private void sign(Project project) {
SigningExtension signing = project.getExtensions().findByType(SigningExtension.class); SigningExtension signing = findAndConfigureSigningExtension(project);
signing.setRequired((Callable<Boolean>) () -> project.getPlugins().withType(PublishAllJavaComponentsPlugin.class).all(publishJavaComponentsPlugin -> {
project.getGradle().getTaskGraph().hasTask("publishArtifacts")); PublishingExtension publishing = project.getExtensions().findByType(PublishingExtension.class);
Publication maven = publishing.getPublications().getByName("mavenJava");
signing.sign(maven);
});
}
String signingKey = (String) project.findProperty("signingKey"); private SigningExtension findAndConfigureSigningExtension(Project project) {
String signingKeyId = (String) project.findProperty("signingKeyId");
String signingPassword = (String) project.findProperty("signingPassword"); SigningExtension signingExtension = project.getExtensions().findByType(SigningExtension.class);
return configurePgpKeys(project, configureSigningRequired(project, signingExtension));
}
private SigningExtension configureSigningRequired(Project project, SigningExtension signing) {
Callable<Boolean> signingRequired =
() -> project.getGradle().getTaskGraph().hasTask("publishArtifacts");
signing.setRequired(signingRequired);
return signing;
}
private SigningExtension configurePgpKeys(Project project, SigningExtension signing) {
String signingKey = Utils.findPropertyAsString(project, "signingKey");
String signingKeyId = resolveSigningKeyId(project);
String signingPassword = Utils.findPropertyAsString(project, "signingPassword");
if (signingKeyId != null) { if (signingKeyId != null) {
signing.useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword); signing.useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword);
@@ -60,10 +102,14 @@ public class SpringSigningPlugin implements Plugin<Project> {
signing.useInMemoryPgpKeys(signingKey, signingPassword); signing.useInMemoryPgpKeys(signingKey, signingPassword);
} }
project.getPlugins().withType(PublishAllJavaComponentsPlugin.class).all(publishingPlugin -> { return signing;
PublishingExtension publishing = project.getExtensions().findByType(PublishingExtension.class); }
Publication maven = publishing.getPublications().getByName("mavenJava");
signing.sign(maven); private String resolveSigningKeyId(Project project) {
});
String signingKeyId = Utils.findPropertyAsString(project, "signingKeyId");
return signingKeyId != null ? signingKeyId
: Utils.findPropertyAsString(project, "signing.keyId");
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,31 +13,33 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.gradle.propdeps package org.springframework.gradle.propdeps
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.plugins.ide.eclipse.EclipsePlugin import org.gradle.plugins.ide.eclipse.EclipsePlugin
/** /**
* Plugin to allow optional and provided dependency configurations to work with the * Gradle {@link Plugin} to allow {@literal optional} and {@literal provided} dependency configurations
* standard gradle 'eclipse' plugin * to work with the standard Gradle {@link EclipsePlugin}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
* @see org.gradle.plugins.ide.eclipse.EclipsePlugin
*/ */
class PropDepsEclipsePlugin implements Plugin<Project> { class PropDepsEclipsePlugin implements Plugin<Project> {
public void apply(Project project) { void apply(Project project) {
project.plugins.apply(PropDepsPlugin) project.plugins.apply(PropDepsPlugin)
project.plugins.apply(EclipsePlugin) project.plugins.apply(EclipsePlugin)
project.eclipse { project.eclipse {
classpath { classpath {
plusConfigurations += [project.configurations.provided, project.configurations.optional] plusConfigurations += [ project.configurations.provided, project.configurations.optional ]
} }
} }
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,34 +13,36 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.gradle.propdeps package org.springframework.gradle.propdeps
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.plugins.ide.idea.IdeaPlugin import org.gradle.plugins.ide.idea.IdeaPlugin
/** /**
* Plugin to allow optional and provided dependency configurations to work with the * Gradle {@link Plugin} to allow {@literal optional} and {@literal provided} dependency configurations
* standard gradle 'idea' plugin * to work with the standard Gradle {@link IdeaPlugin}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Brian Clozel * @author Brian Clozel
* @author John Blum
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
* @see org.gradle.plugins.ide.idea.IdeaPlugin
* @link https://youtrack.jetbrains.com/issue/IDEA-107046 * @link https://youtrack.jetbrains.com/issue/IDEA-107046
* @link https://youtrack.jetbrains.com/issue/IDEA-117668 * @link https://youtrack.jetbrains.com/issue/IDEA-117668
*/ */
class PropDepsIdeaPlugin implements Plugin<Project> { class PropDepsIdeaPlugin implements Plugin<Project> {
public void apply(Project project) { void apply(Project project) {
project.plugins.apply(PropDepsPlugin) project.plugins.apply(PropDepsPlugin)
project.plugins.apply(IdeaPlugin) project.plugins.apply(IdeaPlugin)
project.idea.module { project.idea.module {
// IDEA internally deals with 4 scopes : COMPILE, TEST, PROVIDED, RUNTIME // IntelliJ IDEA internally deals with 4 scopes : COMPILE, TEST, PROVIDED, RUNTIME
// but only PROVIDED seems to be picked up // but only PROVIDED seems to be picked up
scopes.PROVIDED.plus += [project.configurations.provided] scopes.PROVIDED.plus += [ project.configurations.provided ]
scopes.PROVIDED.plus += [project.configurations.optional] scopes.PROVIDED.plus += [ project.configurations.optional ]
} }
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,10 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.gradle.propdeps package org.springframework.gradle.propdeps
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.Configuration
@@ -25,12 +23,13 @@ import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.javadoc.Javadoc import org.gradle.api.tasks.javadoc.Javadoc
/** /**
* Plugin to allow 'optional' and 'provided' dependency configurations * Gradle {@link Plugin} to allow {@literal optional} and {@literal provided} dependency configurations.
* *
* As stated in the maven documentation, provided scope "is only available on the compilation and test classpath, * As stated in the Maven documentation, {@literal provided} scope {@literal "is only available on the compilation
* and is not transitive". * and test classpath, and is not transitive"}.
*
* This {@link Plugin} creates two new configurations, and each one:
* *
* This plugin creates two new configurations, and each one:
* <ul> * <ul>
* <li>is a parent of the compile configuration</li> * <li>is a parent of the compile configuration</li>
* <li>is not visible, not transitive</li> * <li>is not visible, not transitive</li>
@@ -40,27 +39,35 @@ import org.gradle.api.tasks.javadoc.Javadoc
* @author Phillip Webb * @author Phillip Webb
* @author Brian Clozel * @author Brian Clozel
* @author Rob Winch * @author Rob Winch
* @author John Blum
* *
* @see org.gradle.api.Plugin
* @see org.gradle.api.Project
* @see org.springframework.gradle.propdeps.PropDepsEclipsePlugin
* @see org.springframework.gradle.propdeps.PropDepsIdeaPlugin
* @see <a href="https://www.gradle.org/docs/current/userguide/java_plugin.html#N121CF">Maven documentation</a> * @see <a href="https://www.gradle.org/docs/current/userguide/java_plugin.html#N121CF">Maven documentation</a>
* @see <a href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope">Gradle configurations</a> * @see <a href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope">Gradle configurations</a>
* @see PropDepsEclipsePlugin
* @see PropDepsIdeaPlugin
*/ */
class PropDepsPlugin implements Plugin<Project> { class PropDepsPlugin implements Plugin<Project> {
public void apply(Project project) { void apply(Project project) {
project.plugins.apply(JavaPlugin) project.plugins.apply(JavaPlugin)
Configuration provided = addConfiguration(project, "provided")
Configuration optional = addConfiguration(project, "optional") Configuration optional = addConfiguration(project, "optional")
Configuration provided = addConfiguration(project, "provided")
Javadoc javadoc = project.tasks.getByName(JavaPlugin.JAVADOC_TASK_NAME) Javadoc javadoc = project.tasks.getByName(JavaPlugin.JAVADOC_TASK_NAME)
javadoc.classpath = javadoc.classpath.plus(provided).plus(optional)
javadoc.classpath = javadoc.classpath + provided + optional
} }
private Configuration addConfiguration(Project project, String name) { private Configuration addConfiguration(Project project, String name) {
Configuration configuration = project.configurations.create(name) Configuration configuration = project.configurations.create(name)
configuration.extendsFrom(project.configurations.implementation) configuration.extendsFrom(project.configurations.implementation)
project.plugins.withType(JavaLibraryPlugin, { project.plugins.withType(JavaLibraryPlugin, {
configuration.extendsFrom(project.configurations.api) configuration.extendsFrom(project.configurations.api)
}) })
@@ -72,5 +79,4 @@ class PropDepsPlugin implements Plugin<Project> {
return configuration return configuration
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2019-2020 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2019-2020 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2019-2020 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2019-2020 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2019-2020 the original author or authors. * Copyright 2022-present the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1 +1 @@
implementation-class=build.GemFireServerPlugin implementation-class=build.GemFireServerPlugin

View File

@@ -1 +1 @@
implementation-class=io.spring.gradle.convention.SpringDependencyManagementConventionPlugin implementation-class=io.spring.gradle.convention.SpringDependencyManagementConventionsPlugin