Skip to content

Commit 5160a0e

Browse files
committed
Import Spring Build Conventions Gradle Plugins.
1 parent df0709c commit 5160a0e

File tree

56 files changed

+2470
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2470
-0
lines changed

buildSrc/build.gradle

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
plugins {
2+
id "java-gradle-plugin"
3+
id "com.jfrog.artifactory" version '4.9.10'
4+
id 'com.github.ben-manes.versions' version '0.25.0'
5+
}
6+
7+
apply plugin: 'java'
8+
apply plugin: 'groovy'
9+
apply plugin: 'maven'
10+
11+
group 'io.spring.gradle'
12+
13+
sourceCompatibility = 1.8
14+
15+
repositories {
16+
mavenCentral()
17+
gradlePluginPortal()
18+
jcenter()
19+
maven { url 'https://repo.spring.io/plugins-release/' }
20+
}
21+
22+
configurations {
23+
implementation {
24+
exclude module: 'groovy-all'
25+
}
26+
}
27+
28+
dependencies {
29+
30+
implementation localGroovy()
31+
32+
implementation 'com.github.ben-manes:gradle-versions-plugin:0.25.0'
33+
implementation 'gradle.plugin.org.gretty:gretty:3.0.1'
34+
implementation 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.21.1'
35+
implementation 'io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE'
36+
implementation 'io.spring.gradle:propdeps-plugin:0.0.10.RELEASE'
37+
implementation 'io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.15'
38+
implementation 'io.spring.nohttp:nohttp-gradle:0.0.3.RELEASE'
39+
implementation 'org.asciidoctor:asciidoctor-gradle-jvm:3.1.0'
40+
implementation 'org.asciidoctor:asciidoctor-gradle-jvm-pdf:3.1.0'
41+
implementation 'org.hidetake:gradle-ssh-plugin:2.10.1'
42+
implementation 'org.jfrog.buildinfo:build-info-extractor-gradle:4.9.10'
43+
implementation 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1'
44+
45+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2002-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package io.spring.gradle.convention;
18+
19+
import io.spring.gradle.propdeps.PropDepsMavenPlugin;
20+
import org.gradle.api.Plugin;
21+
import org.gradle.api.Project;
22+
import org.gradle.api.plugins.GroovyPlugin;
23+
import org.gradle.api.plugins.JavaPlugin;
24+
import org.gradle.api.plugins.MavenPlugin;
25+
import org.gradle.api.plugins.PluginManager;
26+
import org.gradle.internal.impldep.org.apache.maven.Maven;
27+
import org.gradle.plugins.ide.eclipse.EclipseWtpPlugin;
28+
import org.gradle.plugins.ide.idea.IdeaPlugin;
29+
import io.spring.gradle.propdeps.PropDepsEclipsePlugin;
30+
import io.spring.gradle.propdeps.PropDepsIdeaPlugin;
31+
import io.spring.gradle.propdeps.PropDepsPlugin;
32+
33+
/**
34+
* @author Rob Winch
35+
*/
36+
public abstract class AbstractSpringJavaPlugin implements Plugin<Project> {
37+
38+
@Override
39+
public final void apply(Project project) {
40+
PluginManager pluginManager = project.getPluginManager();
41+
pluginManager.apply(JavaPlugin.class);
42+
pluginManager.apply(ManagementConfigurationPlugin.class);
43+
if (project.file("src/main/groovy").exists()
44+
|| project.file("src/test/groovy").exists()
45+
|| project.file("src/integration-test/groovy").exists()) {
46+
pluginManager.apply(GroovyPlugin.class);
47+
}
48+
pluginManager.apply("io.spring.convention.repository");
49+
pluginManager.apply(EclipseWtpPlugin);
50+
pluginManager.apply(IdeaPlugin);
51+
pluginManager.apply(PropDepsPlugin);
52+
pluginManager.apply(PropDepsEclipsePlugin);
53+
pluginManager.apply(PropDepsIdeaPlugin);
54+
project.getPlugins().withType(MavenPlugin) {
55+
pluginManager.apply(PropDepsMavenPlugin);
56+
}
57+
pluginManager.apply("io.spring.convention.tests-configuration");
58+
pluginManager.apply("io.spring.convention.integration-test");
59+
pluginManager.apply("io.spring.convention.springdependencymangement");
60+
pluginManager.apply("io.spring.convention.dependency-set");
61+
pluginManager.apply("io.spring.convention.javadoc-options");
62+
pluginManager.apply("io.spring.convention.checkstyle");
63+
pluginManager.apply('com.github.ben-manes.versions');
64+
65+
copyPropertyFromRootProjectTo("group", project);
66+
copyPropertyFromRootProjectTo("version", project);
67+
copyPropertyFromRootProjectTo("description", project);
68+
69+
project.jar {
70+
manifest.attributes["Created-By"] =
71+
"${System.getProperty("java.version")} (${System.getProperty("java.specification.vendor")})"
72+
manifest.attributes["Implementation-Title"] = project.name
73+
manifest.attributes["Implementation-Version"] = project.version
74+
manifest.attributes["Automatic-Module-Name"] = project.name.replace('-', '.')
75+
}
76+
additionalPlugins(project);
77+
}
78+
79+
private void copyPropertyFromRootProjectTo(String propertyName, Project project) {
80+
Project rootProject = project.getRootProject();
81+
Object property = rootProject.findProperty(propertyName);
82+
if(property != null) {
83+
project.setProperty(propertyName, property);
84+
}
85+
}
86+
87+
protected abstract void additionalPlugins(Project project);
88+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2002-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package io.spring.gradle.convention
17+
18+
import org.gradle.api.Plugin
19+
import org.gradle.api.Project
20+
21+
class ArtifactoryPlugin implements Plugin<Project> {
22+
23+
@Override
24+
void apply(Project project) {
25+
project.plugins.apply('com.jfrog.artifactory')
26+
String name = Utils.getProjectName(project);
27+
boolean isSnapshot = Utils.isSnapshot(project);
28+
boolean isMilestone = Utils.isMilestone(project);
29+
project.artifactory {
30+
contextUrl = 'https://repo.spring.io'
31+
publish {
32+
repository {
33+
repoKey = isSnapshot ? 'libs-snapshot-local' : isMilestone ? 'libs-milestone-local' : 'libs-release-local'
34+
if(project.hasProperty('artifactoryUsername')) {
35+
username = artifactoryUsername
36+
password = artifactoryPassword
37+
}
38+
}
39+
}
40+
}
41+
42+
project.artifactoryPublish {
43+
publishIvy false
44+
properties = [
45+
'bintray.package': "${project.group}:${name}",
46+
'bintray.version': "${project.version}"
47+
]
48+
}
49+
50+
project.artifactory {
51+
publish {
52+
defaults {
53+
publishConfigs('archives')
54+
}
55+
}
56+
}
57+
}
58+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2016-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package io.spring.gradle.convention
18+
19+
import org.gradle.api.Plugin
20+
import org.gradle.api.Project
21+
import org.gradle.api.plugins.JavaPlugin
22+
23+
/**
24+
* Adds and configures Checkstyle plugin.
25+
*
26+
* @author Vedran Pavic
27+
*/
28+
class CheckstylePlugin implements Plugin<Project> {
29+
30+
final CHECKSTYLE_DIR = 'etc/checkstyle'
31+
32+
@Override
33+
void apply(Project project) {
34+
project.plugins.withType(JavaPlugin) {
35+
def checkstyleDir = project.rootProject.file(CHECKSTYLE_DIR)
36+
if (checkstyleDir.exists() && checkstyleDir.directory) {
37+
project.getPluginManager().apply('checkstyle')
38+
project.dependencies.add('checkstyle', 'io.spring.javaformat:spring-javaformat-checkstyle:0.0.15')
39+
project.dependencies.add('checkstyle', 'io.spring.nohttp:nohttp-checkstyle:0.0.3.RELEASE')
40+
41+
project.checkstyle {
42+
configDir = checkstyleDir
43+
toolVersion = '8.21'
44+
}
45+
}
46+
}
47+
}
48+
49+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package io.spring.gradle.convention
2+
3+
import org.gradle.api.Project
4+
import org.gradle.api.artifacts.component.ModuleComponentSelector
5+
import org.gradle.api.tasks.Input
6+
import org.gradle.api.tasks.Internal;
7+
8+
import java.io.File;
9+
import java.io.FileOutputStream;
10+
import java.io.IOException;
11+
import java.io.OutputStream;
12+
import java.util.Map;
13+
import java.util.Properties;
14+
15+
import org.gradle.api.DefaultTask;
16+
import org.gradle.api.artifacts.Configuration;
17+
import org.gradle.api.tasks.TaskAction;
18+
19+
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension;
20+
21+
public class DependencyManagementExportTask extends DefaultTask {
22+
@Internal
23+
def projects;
24+
25+
@Input
26+
String getProjectNames() {
27+
return projects*.name
28+
}
29+
30+
@TaskAction
31+
public void dependencyManagementExport() throws IOException {
32+
def projects = this.projects ?: project.subprojects + project
33+
def configurations = projects*.configurations*.findAll { ['testRuntime','integrationTestRuntime','grettyRunnerTomcat8','ajtools'].contains(it.name) }
34+
def dependencyResults = configurations*.incoming*.resolutionResult*.allDependencies.flatten()
35+
def moduleVersionVersions = dependencyResults.findAll { r -> r.requested instanceof ModuleComponentSelector }.collect { r-> r.selected.moduleVersion }
36+
37+
def projectDependencies = projects.collect { p-> "${p.group}:${p.name}:${p.version}".toString() } as Set
38+
def dependencies = moduleVersionVersions.collect { d ->
39+
"${d.group}:${d.name}:${d.version}".toString()
40+
}.sort() as Set
41+
42+
println ''
43+
println ''
44+
println 'dependencyManagement {'
45+
println '\tdependencies {'
46+
dependencies.findAll { d-> !projectDependencies.contains(d)}.each {
47+
println "\t\tdependency '$it'"
48+
}
49+
println '\t}'
50+
println '}'
51+
println ''
52+
println ''
53+
println 'TIP Use this to find duplicates:\n$ sort gradle/dependency-management.gradle| uniq -c | grep -v \'^\\s*1\''
54+
println ''
55+
println ''
56+
}
57+
58+
void setOutputFile(File file) throws IOException {
59+
this.output = new FileOutputStream(file);
60+
}
61+
}

0 commit comments

Comments
 (0)