Skip to content

Commit 39c4519

Browse files
committed
Add gradle build files
- First set of changes for introduction of a gradle build. - Relates spring-projects#470
1 parent a143d25 commit 39c4519

32 files changed

+1425
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
.settings/
44

55
target/
6+
build/
7+
bin/
8+
.jfrog/
69

10+
.gradle
711
.idea/
812
*.iml
913
*.ipr

build.gradle

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
plugins {
2+
id "base"
3+
id 'org.springframework.shell.root'
4+
}
5+
6+
description = 'Spring Shell'
7+
8+
repositories {
9+
maven { url 'https://repo.spring.io/snapshot' }
10+
maven { url 'https://repo.spring.io/milestone' }
11+
maven { url 'https://repo.spring.io/release' }
12+
mavenCentral()
13+
}
14+
15+
allprojects {
16+
group = 'org.springframework.shell'
17+
18+
repositories {
19+
mavenCentral()
20+
maven { url 'https://repo.spring.io/release' }
21+
if (version.contains('-')) {
22+
maven { url "https://repo.spring.io/milestone" }
23+
}
24+
if (version.endsWith('-SNAPSHOT')) {
25+
maven { url "https://repo.spring.io/snapshot" }
26+
}
27+
}
28+
29+
configurations.all {
30+
resolutionStrategy.cacheChangingModulesFor 1, 'hours'
31+
}
32+
}

buildSrc/build.gradle

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
plugins {
2+
id "java-gradle-plugin"
3+
id "java"
4+
}
5+
6+
sourceCompatibility = JavaVersion.VERSION_17
7+
8+
repositories {
9+
gradlePluginPortal()
10+
mavenCentral()
11+
maven { url 'https://repo.spring.io/plugins-release/' }
12+
maven { url "https://repo.spring.io/snapshot" }
13+
}
14+
15+
ext {
16+
def propertiesFile = new File(new File("$projectDir").parentFile, "gradle.properties")
17+
propertiesFile.withInputStream {
18+
def properties = new Properties()
19+
properties.load(it)
20+
set("springBootVersion", properties["springBootVersion"])
21+
}
22+
}
23+
24+
dependencies {
25+
implementation(platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}"))
26+
implementation("org.springframework:spring-core")
27+
implementation 'org.asciidoctor:asciidoctor-gradle-jvm:3.3.2'
28+
implementation 'org.jfrog.buildinfo:build-info-extractor-gradle:4.29.0'
29+
}
30+
31+
gradlePlugin {
32+
plugins {
33+
modulePlugin {
34+
id = "org.springframework.shell.module"
35+
implementationClass = "org.springframework.shell.gradle.ModulePlugin"
36+
}
37+
starterPlugin {
38+
id = "org.springframework.shell.starter"
39+
implementationClass = "org.springframework.shell.gradle.StarterPlugin"
40+
}
41+
bomPlugin {
42+
id = "org.springframework.shell.bom"
43+
implementationClass = "org.springframework.shell.gradle.BomPlugin"
44+
}
45+
docsPlugin {
46+
id = "org.springframework.shell.docs"
47+
implementationClass = "org.springframework.shell.gradle.DocsPlugin"
48+
}
49+
distPlugin {
50+
id = "org.springframework.shell.root"
51+
implementationClass = "org.springframework.shell.gradle.RootPlugin"
52+
}
53+
samplePlugin {
54+
id = "org.springframework.shell.sample"
55+
implementationClass = "org.springframework.shell.gradle.SamplePlugin"
56+
}
57+
}
58+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of 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,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.shell.gradle;
17+
18+
import java.util.HashMap;
19+
import java.util.Map;
20+
21+
import org.gradle.api.Project;
22+
import org.gradle.api.Task;
23+
import org.gradle.api.plugins.PluginManager;
24+
import org.jfrog.build.extractor.clientConfiguration.ArtifactSpec;
25+
import org.jfrog.build.extractor.clientConfiguration.ArtifactSpecs;
26+
import org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin;
27+
import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask;
28+
29+
/**
30+
* @author Janne Valkealahti
31+
*/
32+
public class ArtifactoryConventions {
33+
34+
void apply(Project project) {
35+
PluginManager pluginManager = project.getPluginManager();
36+
pluginManager.apply(ArtifactoryPlugin.class);
37+
38+
project.getPlugins().withType(ArtifactoryPlugin.class, artifactory -> {
39+
Task task = project.getTasks().findByName(ArtifactoryTask.ARTIFACTORY_PUBLISH_TASK_NAME);
40+
if (task != null) {
41+
ArtifactoryTask aTask = (ArtifactoryTask) task;
42+
aTask.setCiServerBuild();
43+
// bom is not a java project so plugin doesn't
44+
// add defaults for publications.
45+
aTask.publications("mavenJava");
46+
aTask.publishConfigs("archives");
47+
48+
// plugin is difficult to work with, use this hack
49+
// to set props before task does its real work
50+
task.doFirst(t -> {
51+
// this needs mods if we ever have zips other than
52+
// docs zip having asciidoc/javadoc.
53+
ArtifactoryTask at = (ArtifactoryTask) t;
54+
ArtifactSpecs artifactSpecs = at.getArtifactSpecs();
55+
Map<String, String> propsMap = new HashMap<>();
56+
propsMap.put("zip.deployed", "false");
57+
propsMap.put("zip.type", "docs");
58+
ArtifactSpec spec = ArtifactSpec.builder()
59+
.artifactNotation("*:*:*:*@zip")
60+
// archives is manually set for zip in root plugin
61+
.configuration("archives")
62+
.properties(propsMap)
63+
.build();
64+
artifactSpecs.add(spec);
65+
});
66+
}
67+
});
68+
}
69+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of 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,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.shell.gradle;
17+
18+
import org.gradle.api.Plugin;
19+
import org.gradle.api.Project;
20+
import org.gradle.api.artifacts.dsl.DependencyConstraintHandler;
21+
import org.gradle.api.plugins.JavaPlatformPlugin;
22+
import org.gradle.api.plugins.PluginManager;
23+
24+
/**
25+
* @author Janne Valkealahti
26+
*/
27+
class BomPlugin implements Plugin<Project> {
28+
29+
@Override
30+
public void apply(Project project) {
31+
PluginManager pluginManager = project.getPluginManager();
32+
pluginManager.apply(SpringMavenPlugin.class);
33+
pluginManager.apply(JavaPlatformPlugin.class);
34+
new ArtifactoryConventions().apply(project);
35+
36+
// bom should have main shell modules and starters
37+
DependencyConstraintHandler constraints = project.getDependencies().getConstraints();
38+
project.getRootProject().getAllprojects().forEach(p -> {
39+
p.getPlugins().withType(ModulePlugin.class, m -> {
40+
constraints.add("api", p);
41+
});
42+
p.getPlugins().withType(StarterPlugin.class, m -> {
43+
constraints.add("api", p);
44+
});
45+
});
46+
}
47+
}

0 commit comments

Comments
 (0)