Skip to content

Commit

Permalink
Introduce build conventions to reduce repetition in build.gradle files
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Jul 2, 2024
1 parent c8c04b4 commit fa2879f
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 214 deletions.
68 changes: 1 addition & 67 deletions gradle-enterprise-conventions-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,91 +1,25 @@
plugins {
id "checkstyle"
id "io.spring.javaformat" version "$javaFormatVersion"
id "build-conventions"
id "java"
id "maven-publish"
}

description = "Gradle Enterprise Conventions Core"
group = 'io.spring.ge.conventions'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}")

testImplementation("org.assertj:assertj-core:3.24.2")
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
testImplementation("org.mockito:mockito-core:4.11.0")
}

test {
useJUnitPlatform()
}

java {
withJavadocJar()
withSourcesJar()
}

checkstyle {
def archive = configurations.checkstyle.filter { it.name.startsWith("spring-javaformat-checkstyle")}
config = resources.text.fromArchiveEntry(archive, "io/spring/javaformat/checkstyle/checkstyle.xml")
toolVersion = 9.3
}

tasks.withType(GenerateModuleMetadata).all {
enabled = false
}

if (project.hasProperty("distributionRepository")) {
publishing {
repositories {
maven {
url = "${distributionRepository}"
name = "deployment"
}
}
}
}

publishing {
publications {
maven(MavenPublication) {
from components.java
}
withType(MavenPublication) { mavenPublication ->
pom {
name = project.description
description = project.description
url = 'https://github.com/spring-io/gradle-enterprise-conventions'
organization {
name = 'Pivotal Software, Inc.'
url = 'https://spring.io'
}
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
scm {
url = 'https://github.com/spring-io/gradle-enterprise-conventions'
connection = 'scm:git:https://github.com/spring-io/gradle-enterprise-conventions'
}
developers {
developer {
id = 'wilkinsona'
name = 'Andy Wilkinson'
email = 'awilkinson@pivotal.io'
roles = ["Project lead"]
}
}
}
}
}
}
73 changes: 1 addition & 72 deletions gradle-enterprise-conventions-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
plugins {
id "checkstyle"
id "io.spring.javaformat" version "$javaFormatVersion"
id "build-conventions"
id "java-gradle-plugin"
id "maven-publish"
}

description = "Gradle Enterprise Conventions Gradle plugin"
group = 'io.spring.ge.conventions'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}")

compileOnly("com.gradle:develocity-gradle-plugin:${gradleEnterprisePluginVersion}")

implementation(project(":gradle-enterprise-conventions-core"))
Expand All @@ -39,67 +32,3 @@ gradlePlugin {
}
}
}

test {
useJUnitPlatform()
}

java {
withJavadocJar()
withSourcesJar()
}

checkstyle {
def archive = configurations.checkstyle.filter { it.name.startsWith("spring-javaformat-checkstyle")}
config = resources.text.fromArchiveEntry(archive, "io/spring/javaformat/checkstyle/checkstyle.xml")
toolVersion = 9.3
}

tasks.withType(GenerateModuleMetadata).all {
enabled = false
}

if (project.hasProperty("distributionRepository")) {
publishing {
repositories {
maven {
url = "${distributionRepository}"
name = "deployment"
}
}
}
}

publishing {
publications {
withType(MavenPublication) { mavenPublication ->
pom {
name = project.description
description = project.description
url = 'https://github.com/spring-io/gradle-enterprise-conventions'
organization {
name = 'Pivotal Software, Inc.'
url = 'https://spring.io'
}
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
scm {
url = 'https://github.com/spring-io/gradle-enterprise-conventions'
connection = 'scm:git:https://github.com/spring-io/gradle-enterprise-conventions'
}
developers {
developer {
id = 'wilkinsona'
name = 'Andy Wilkinson'
email = 'awilkinson@pivotal.io'
roles = ["Project lead"]
}
}
}
}
}
}
76 changes: 1 addition & 75 deletions gradle-enterprise-conventions-maven-extension/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
plugins {
id "checkstyle"
id "io.spring.javaformat" version "$javaFormatVersion"
id "build-conventions"
id "java"
id "maven-publish"
}

description = "Gradle Enterprise Conventions Maven extension"
group = 'io.spring.ge.conventions'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}")

compileOnly("org.apache.maven:maven-core:3.6.3")
compileOnly("org.codehaus.plexus:plexus-component-annotations:1.7.1")

Expand All @@ -29,77 +22,10 @@ dependencies {
testImplementation("org.mockito:mockito-core:4.11.0")
}

tasks.withType(Test) { testTask ->
if (testTask.name.startsWith("compatibilityTest_")) {
testTask.filter {
includeTestsMatching "*IntegrationTests"
}
}
}

test {
useJUnitPlatform()
}

java {
withJavadocJar()
withSourcesJar()
}

checkstyle {
def archive = configurations.checkstyle.filter { it.name.startsWith("spring-javaformat-checkstyle")}
config = resources.text.fromArchiveEntry(archive, "io/spring/javaformat/checkstyle/checkstyle.xml")
toolVersion = 9.3
}

tasks.withType(GenerateModuleMetadata).all {
enabled = false
}

if (project.hasProperty("distributionRepository")) {
publishing {
repositories {
maven {
url = "${distributionRepository}"
name = "deployment"
}
}
}
}

publishing {
publications {
maven(MavenPublication) {
from components.java
}
withType(MavenPublication) { mavenPublication ->
pom {
name = project.description
description = project.description
url = 'https://github.com/spring-io/gradle-enterprise-conventions'
organization {
name = 'Pivotal Software, Inc.'
url = 'https://spring.io'
}
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
scm {
url = 'https://github.com/spring-io/gradle-enterprise-conventions'
connection = 'scm:git:https://github.com/spring-io/gradle-enterprise-conventions'
}
developers {
developer {
id = 'wilkinsona'
name = 'Andy Wilkinson'
email = 'awilkinson@pivotal.io'
roles = ["Project lead"]
}
}
}
}
}
}
32 changes: 32 additions & 0 deletions gradle/plugins/build-conventions/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins {
id "checkstyle"
id "java-gradle-plugin"
id "io.spring.javaformat" version "0.0.39"
}

repositories {
mavenCentral()
}

gradlePlugin {
plugins {
conventionsPlugin {
id = "build-conventions"
implementationClass = "io.spring.ge.conventions.build.BuildConventionsPlugin"
}
}
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

dependencies {
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.39")
implementation("io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.39")
}

checkstyle {
def archive = configurations.checkstyle.filter { it.name.startsWith("spring-javaformat-checkstyle")}
config = resources.text.fromArchiveEntry(archive, "io/spring/javaformat/checkstyle/checkstyle.xml")
toolVersion = 9.3
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2020-2024 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.ge.conventions.build;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;

public class BuildConventionsPlugin implements Plugin<Project> {

@Override
public void apply(Project target) {
target.getPlugins().withType(JavaPlugin.class, (plugin) -> new JavaConventions().apply(target));
target.getPlugins().withType(MavenPublishPlugin.class, (plugin) -> new MavenPublishConventions().apply(target));
}

}
Loading

0 comments on commit fa2879f

Please sign in to comment.