Port the build to Gradle
Closes gh-1457
This commit is contained in:
committed by
Stéphane Nicoll
parent
3a60f3638e
commit
49e6c9a70f
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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.ws.gradle.conventions;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaBasePlugin;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
|
||||
|
||||
/**
|
||||
* {@link Plugin} to apply conventions to a {@link Project} by reacting to its plugins and
|
||||
* configuring them.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ConventionsPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.setGroup("org.springframework.ws");
|
||||
project.getPlugins()
|
||||
.withType(JavaBasePlugin.class)
|
||||
.all((plugin) -> new JavaBasePluginConventions().apply(project));
|
||||
project.getPlugins().withType(JavaPlugin.class).all((plugin) -> new JavaPluginConventions().apply(project));
|
||||
project.getPlugins()
|
||||
.withType(MavenPublishPlugin.class)
|
||||
.all((plugin) -> new MavenPublishPluginConventions().apply(project));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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.ws.gradle.conventions;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaBasePlugin;
|
||||
import org.gradle.api.tasks.javadoc.Javadoc;
|
||||
import org.gradle.external.javadoc.CoreJavadocOptions;
|
||||
import org.gradle.external.javadoc.MinimalJavadocOptions;
|
||||
|
||||
/**
|
||||
* Conventions for the {@link JavaBasePlugin}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class JavaBasePluginConventions {
|
||||
|
||||
void apply(Project project) {
|
||||
project.getTasks().withType(Javadoc.class).configureEach((javadoc) -> {
|
||||
MinimalJavadocOptions options = javadoc.getOptions();
|
||||
options.quiet();
|
||||
options.source(JavaPluginConventions.JAVA_BASELINE.getMajorVersion());
|
||||
if (options instanceof CoreJavadocOptions coreOptions) {
|
||||
coreOptions.addBooleanOption("Xdoclint:-missing", true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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.ws.gradle.conventions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.spring.javaformat.gradle.SpringJavaFormatPlugin;
|
||||
import org.gradle.api.JavaVersion;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.ConfigurationContainer;
|
||||
import org.gradle.api.artifacts.dsl.DependencyHandler;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.bundling.Jar;
|
||||
import org.gradle.api.tasks.testing.Test;
|
||||
import org.gradle.jvm.toolchain.JavaLanguageVersion;
|
||||
|
||||
/**
|
||||
* Conventions for the {@link JavaPlugin}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class JavaPluginConventions {
|
||||
|
||||
static final JavaVersion JAVA_BASELINE = JavaVersion.VERSION_17;
|
||||
|
||||
void apply(Project project) {
|
||||
project.getPlugins().apply(SpringJavaFormatPlugin.class);
|
||||
JavaPluginExtension java = project.getExtensions().getByType(JavaPluginExtension.class);
|
||||
configureRepositories(project);
|
||||
enableSourceAndJavadocJars(java);
|
||||
configureSourceAndTargetCompatibility(java);
|
||||
configureDependencyManagement(project);
|
||||
configureJarManifest(project);
|
||||
configureToolchain(project, java);
|
||||
configureJavadocClasspath(project, java);
|
||||
configureJUnitPlatform(project);
|
||||
}
|
||||
|
||||
private void configureRepositories(Project project) {
|
||||
project.getRepositories().mavenCentral();
|
||||
String version = project.getVersion().toString();
|
||||
if (version.contains("-")) {
|
||||
project.getRepositories().maven((repository) -> {
|
||||
repository.setName("Spring Milestones");
|
||||
repository.setUrl("https://repo.spring.io/milestone");
|
||||
});
|
||||
}
|
||||
if (version.endsWith("-SNAPSHOT")) {
|
||||
project.getRepositories().maven((repository) -> {
|
||||
repository.setName("Spring Snapshots");
|
||||
repository.setUrl("https://repo.spring.io/snapshot");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void enableSourceAndJavadocJars(JavaPluginExtension java) {
|
||||
java.withSourcesJar();
|
||||
java.withJavadocJar();
|
||||
}
|
||||
|
||||
private void configureSourceAndTargetCompatibility(JavaPluginExtension java) {
|
||||
java.setSourceCompatibility(JAVA_BASELINE);
|
||||
java.setTargetCompatibility(JAVA_BASELINE);
|
||||
}
|
||||
|
||||
private void configureDependencyManagement(Project project) {
|
||||
ConfigurationContainer configurations = project.getConfigurations();
|
||||
Configuration dependencyManagement = configurations.create("dependencyManagement", (configuration) -> {
|
||||
configuration.setCanBeConsumed(false);
|
||||
configuration.setCanBeResolved(false);
|
||||
configuration.setVisible(false);
|
||||
});
|
||||
configurations.matching((candidate) -> candidate.getName().endsWith("Classpath"))
|
||||
.all((classpath) -> classpath.extendsFrom(dependencyManagement));
|
||||
DependencyHandler dependencies = project.getDependencies();
|
||||
dependencyManagement.getDependencies()
|
||||
.add(dependencies.enforcedPlatform(dependencies.project(Map.of("path", ":spring-ws-platform"))));
|
||||
}
|
||||
|
||||
private void configureJarManifest(Project project) {
|
||||
project.getTasks()
|
||||
.named("jar", Jar.class,
|
||||
(jar) -> jar.manifest((manifest) -> manifest.attributes(Map.of("Build-Jdk-Spec",
|
||||
JAVA_BASELINE.getMajorVersion(), "Built-By", "Spring", "Implementation-Title",
|
||||
project.getDescription(), "Implementation-Version", project.getVersion()))));
|
||||
}
|
||||
|
||||
private void configureToolchain(Project project, JavaPluginExtension java) {
|
||||
Object toolchainVersion = project.findProperty("toolchainVersion");
|
||||
if (toolchainVersion != null) {
|
||||
java.getToolchain().getLanguageVersion().set(JavaLanguageVersion.of(toolchainVersion.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private void configureJavadocClasspath(Project project, JavaPluginExtension java) {
|
||||
project.getConfigurations().create("javadocClasspath", (javadocClasspath) -> {
|
||||
javadocClasspath.setCanBeConsumed(true);
|
||||
javadocClasspath.setCanBeResolved(false);
|
||||
javadocClasspath.extendsFrom(project.getConfigurations()
|
||||
.getByName(java.getSourceSets()
|
||||
.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
|
||||
.getCompileClasspathConfigurationName()));
|
||||
});
|
||||
}
|
||||
|
||||
private void configureJUnitPlatform(Project project) {
|
||||
project.getTasks().withType(Test.class).configureEach((task) -> task.useJUnitPlatform());
|
||||
project.getDependencies().add("testRuntimeOnly", "org.junit.platform:junit-platform-launcher");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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.ws.gradle.conventions;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPlatformPlugin;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.publish.PublishingExtension;
|
||||
import org.gradle.api.publish.maven.MavenPublication;
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
|
||||
|
||||
/**
|
||||
* Conventions for the {@link MavenPublishPlugin}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class MavenPublishPluginConventions {
|
||||
|
||||
void apply(Project project) {
|
||||
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
|
||||
configureRepositories(project, publishing);
|
||||
project.getPlugins().withType(JavaPlugin.class).all((javaPlugin) -> {
|
||||
publishing.getPublications().create("maven", MavenPublication.class, (publication) -> {
|
||||
publication.from(project.getComponents().getByName("java"));
|
||||
publication.versionMapping((strategy) -> {
|
||||
strategy.usage("java-api",
|
||||
(variantStrategy) -> variantStrategy.fromResolutionOf("runtimeClasspath"));
|
||||
strategy.usage("java-runtime", (variantStrategy) -> variantStrategy.fromResolutionResult());
|
||||
});
|
||||
configurePom(publication);
|
||||
});
|
||||
});
|
||||
project.getPlugins().withType(JavaPlatformPlugin.class).all((javaPlatformPlugin) -> {
|
||||
publishing.getPublications().create("maven", MavenPublication.class, (publication) -> {
|
||||
publication.from(project.getComponents().getByName("javaPlatform"));
|
||||
configurePom(publication);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void configureRepositories(Project project, PublishingExtension publishing) {
|
||||
Object deploymentRepository = project.findProperty("deploymentRepository");
|
||||
if (deploymentRepository != null) {
|
||||
publishing.getRepositories().maven((maven) -> {
|
||||
maven.setName("deployment");
|
||||
maven.setUrl(deploymentRepository);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void configurePom(MavenPublication mavenPublication) {
|
||||
String organizationName = "Broadcom Inc.";
|
||||
String organizationUrl = "https://www.spring.io";
|
||||
mavenPublication.pom((pom) -> {
|
||||
pom.developers((developers) -> developers.developer((developer) -> {
|
||||
developer.getName().set("Spring");
|
||||
developer.getEmail().set("ask@spring.io");
|
||||
developer.getOrganization().set(organizationName);
|
||||
developer.getOrganizationUrl().set(organizationUrl);
|
||||
}));
|
||||
pom.licenses((licenses) -> licenses.license((license) -> {
|
||||
license.getName().set("The Apache License, Version 2.0");
|
||||
license.getUrl().set("http://www.apache.org/licenses/LICENSE-2.0.txt");
|
||||
}));
|
||||
pom.organization((organization) -> {
|
||||
organization.getName().set(organizationName);
|
||||
organization.getUrl().set(organizationUrl);
|
||||
});
|
||||
pom.scm((scm) -> {
|
||||
scm.getConnection().set("scm:git:git://github.com/spring-projects/spring-ws.git");
|
||||
scm.getDeveloperConnection().set("scm:git:ssh://git@github.com:spring-projects/spring-ws.git");
|
||||
scm.getUrl().set("https://github.com/spring-projects/spring-ws");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2005-2025 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gradle build conventions.
|
||||
*/
|
||||
package org.springframework.ws.gradle.conventions;
|
||||
Reference in New Issue
Block a user