From ea5d38beb9fc3b91a0d51f96fe610efe7cd54034 Mon Sep 17 00:00:00 2001 From: Andy Coates <8012398+big-andy-coates@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:00:32 +0000 Subject: [PATCH] release_prep: update to latest build conventions (#110) * release_prep: update to latest build conventions --- .github/PULL_REQUEST_TEMPLATE.md | 13 ++ .github/dependabot.yml | 2 +- .github/release.yml | 21 ++ .github/workflows/build.yml | 70 +++++++ .github/workflows/codeql.yml | 4 - .github/workflows/gradle.yml | 44 ----- .github/workflows/release.yml | 33 ++++ .github/workflows/version.yml | 28 ++- .gitignore | 3 + README.md | 6 +- build.gradle.kts | 181 ++---------------- buildSrc/build.gradle.kts | 35 ++++ buildSrc/settings.gradle.kts | 0 .../kotlin/creek-common-convention.gradle.kts | 117 +++++++++++ .../creek-coverage-convention.gradle.kts | 74 +++++++ .../kotlin/creek-module-convention.gradle.kts | 30 +++ ...ek-plugin-publishing-convention.gradle.kts | 144 ++++++++++++++ .../creek-publishing-convention.gradle.kts | 130 +++++++++++++ ...-sonatype-publishing-convention.gradle.kts | 43 +++++ 19 files changed, 750 insertions(+), 228 deletions(-) create mode 100644 .github/release.yml create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/gradle.yml create mode 100644 .github/workflows/release.yml create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/settings.gradle.kts create mode 100644 buildSrc/src/main/kotlin/creek-common-convention.gradle.kts create mode 100644 buildSrc/src/main/kotlin/creek-coverage-convention.gradle.kts create mode 100644 buildSrc/src/main/kotlin/creek-module-convention.gradle.kts create mode 100644 buildSrc/src/main/kotlin/creek-plugin-publishing-convention.gradle.kts create mode 100644 buildSrc/src/main/kotlin/creek-publishing-convention.gradle.kts create mode 100644 buildSrc/src/main/kotlin/creek-sonatype-publishing-convention.gradle.kts diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 344a42f..7ddc680 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,3 +1,16 @@ +### Labels +Mark your PRs with the following labels, as appropriate: +- `breaking-change`: if the PR includes a breaking change +- `enhancement`: if the PR enables / completes a new feature +- `bug`: if the PR fixes a bug. +- `dependencies`: if the PR updates dependencies +- `documentation **`: If the PR doc-only changes +- `subtask **`: If the PR is only part of a new feature. Ensure final PR is marked with `enhancement`. +- `chore **`: a maintenance / non-feature released task of no interest to users. + +Labels marked with `**` are excluded from release notes + ### Reviewer checklist - [ ] Ensure relevant issues are linked (description should include text like "Fixes #") +- [ ] Ensure correct labels applied - [ ] Ensure any appropriate documentation has been added or amended \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 5ce918f..6a56573 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -20,4 +20,4 @@ updates: registries: - creek-github-packages schedule: - interval: weekly + interval: monthly \ No newline at end of file diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..8681c94 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,21 @@ +changelog: + exclude: + labels: + - documentation + - subtask + - chore + categories: + - title: Breaking Changes 🛠 + labels: [ breaking-change ] + + - title: Exciting New Features 🎉 + labels: [ enhancement ] + + - title: Bug Fixes 🎉 + labels: [ bug ] + + - title: Dependency Updates + labels: [ dependencies ] + + - title: Less Exciting Things + labels: [ "*" ] \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..0429102 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,70 @@ +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Build + +on: + push: + branches: [ main ] + tags: [ "v*.*.*" ] + pull_request: + branches: [ main ] + workflow_dispatch: + inputs: + publish_artifacts: + description: "Publish release artifacts: true or false?" + default: "true" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3.1.0 + - name: Fetch version history + # Do NOT want to fetch all tags if build specific tag. + # Doing so could result in code published with wrong version, if newer tags have been pushed + if: (!startsWith(github.ref, 'refs/tags/')) + run: git fetch --tag --unshallow + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'adopt' + cache: gradle + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build + env: + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + run: ./gradlew javadoc check coveralls + - name: Publish + if: github.event_name == 'push' || github.event.inputs.publish_artifacts == 'true' + env: + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }} + ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }} + ORG_GRADLE_PROJECT_SONA_USERNAME: ${{ secrets.SONA_USERNAME }} + ORG_GRADLE_PROJECT_SONA_PASSWORD: ${{ secrets.SONA_PASSWORD }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + ./gradlew cV + ./gradlew publish closeAndReleaseStagingRepository + - name: Publish to Gradle Plugins Portal + if: startsWith(github.ref, 'refs/tags/') && !endsWith(github.ref, '-alpha') + env: + GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }} + GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }} + run: | + ./gradlew -Dgradle.publish.key="$GRADLE_PUBLISH_KEY" -Dgradle.publish.secret="$GRADLE_PUBLISH_SECRET" publishPlugins + + create-gh-release: + if: startsWith(github.ref, 'refs/tags/') && !endsWith(github.ref, '-alpha') + needs: build + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v3.1.0 + - name: Create GitHut Release + uses: softprops/action-gh-release@v1 + with: + generate_release_notes: true \ No newline at end of file diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 9fa0f7c..9d1b775 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,8 +1,6 @@ name: CodeQL on: - push: - branches: [ main ] pull_request: branches: [ main ] @@ -40,8 +38,6 @@ jobs: run: chmod +x gradlew - name: Build - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: ./gradlew test - name: Perform CodeQL Analysis diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml deleted file mode 100644 index c5987cf..0000000 --- a/.github/workflows/gradle.yml +++ /dev/null @@ -1,44 +0,0 @@ -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - -name: Build - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - workflow_dispatch: - inputs: - publish: - description: "Publish: true or false?" - required: true - default: "false" - schedule: - - cron: '0 0 * * 0' - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3.1.0 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'adopt' - cache: gradle - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Build - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} - run: ./gradlew check coveralls - - name: Publish - if: github.event_name == 'push' || github.event.inputs.publish == 'true' - run: | - git fetch --tags --unshallow - ./gradlew publish - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..aa8a8c5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,33 @@ +# A Workflow for triggering a new release. + +name: Release + +on: [workflow_dispatch] + +concurrency: "${{ github.repository }}-versioning" + +jobs: + release: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + steps: + - uses: actions/checkout@v3.1.0 + with: + token: ${{ secrets.TRIGGER_GITHUB_TOKEN }} + - name: Fetch version history + run: git fetch --tags --unshallow + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'adopt' + cache: gradle + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Ensure build is green + run: ./gradlew check + - name: Release + run: | + # The following command will trigger the build.yml workflow as it pushes a release tag + ./gradlew release + diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml index f3c7fda..9ea2b5a 100644 --- a/.github/workflows/version.yml +++ b/.github/workflows/version.yml @@ -1,18 +1,27 @@ -name: Version +# A Workflow for adjusting the version number of the next release + +name: Set next version on: workflow_dispatch: inputs: part: - description: "Part to increment: Major, Minor or Patch" + description: "Part to increment: Major, Minor, Patch or the next release, e.g. 1.2.3" required: true - default: Patch + default: Minor + +concurrency: "${{ github.repository }}-versioning" jobs: version: + if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3.1.0 + with: + token: ${{ secrets.TRIGGER_GITHUB_TOKEN }} + - name: Fetch version history + run: git fetch --tags --unshallow - name: Set up JDK 11 uses: actions/setup-java@v3 with: @@ -21,12 +30,13 @@ jobs: cache: gradle - name: Grant execute permission for gradlew run: chmod +x gradlew - - name: Increment Version Part + - name: Increment version + if: contains(fromJson('["Major", "Minor", "Patch"]'), github.event.inputs.part) run: | - git fetch --tags --unshallow + # The following command will trigger the build.yml workflow as it pushes a alpha tag ./gradlew markNextVersion -Prelease.incrementer=increment${{ github.event.inputs.part }} - - name: Trigger Build + - name: Set next version + if: (!contains(fromJson('["Major", "Minor", "Patch"]'), github.event.inputs.part)) run: | - curl -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${GITHUB_TOKEN}" "https://api.github.com/repos/${{ github.repository }}/actions/workflows/gradle.yml/dispatches" -d '{"ref":"main","inputs":{"publish":"true"}}' - env: - GITHUB_TOKEN: ${{ secrets.TRIGGER_GITHUB_TOKEN }} + # The following command will trigger the build.yml workflow as it pushes a alpha tag + ./gradlew markNextVersion -Prelease.version=${{ github.event.inputs.part }} diff --git a/.gitignore b/.gitignore index 8dd0d36..18d6b75 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ out *.ipr *.iws .idea + +# Apple +**/.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index d6cc967..c28681c 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,16 @@ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Coverage Status](https://coveralls.io/repos/github/creek-service/creek-service/badge.svg?branch=main)](https://coveralls.io/github/creek-service/creek-service?branch=main) -[![build](https://github.com/creek-service/creek-service/actions/workflows/gradle.yml/badge.svg)](https://github.com/creek-service/creek-service/actions/workflows/gradle.yml) +[![build](https://github.com/creek-service/creek-service/actions/workflows/build.yml/badge.svg)](https://github.com/creek-service/creek-service/actions/workflows/build.yml) [![CodeQL](https://github.com/creek-service/creek-service/actions/workflows/codeql.yml/badge.svg)](https://github.com/creek-service/creek-service/actions/workflows/codeql.yml) # Creek Service The core of the Creek system. +See [CreekService.org](https://www.creekservice.org) for info on Creek Service. + +## Modules + * **[context](context)**: Provides features to make it easier to write Kafka and Kafka Streams based microservices. * **[extension](extension)**: Contains base types used to implement a Creek service extension and a means of loading extensions * **[test-java-eight](test-java-eight)**: Contains functional testing extension loading *without* Java 9 modularity diff --git a/build.gradle.kts b/build.gradle.kts index 7e066dc..5bc87e1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,52 +1,26 @@ plugins { java jacoco - `maven-publish` - id("com.github.spotbugs") version "5.0.13" // https://plugins.gradle.org/plugin/com.github.spotbugs - id("com.diffplug.spotless") version "6.11.0" // https://mvnrepository.com/artifact/com.diffplug.spotless/spotless-plugin-gradle - id("pl.allegro.tech.build.axion-release") version "1.14.2" // https://mvnrepository.com/artifact/pl.allegro.tech.build.axion-release/pl.allegro.tech.build.axion-release.gradle.plugin?repo=gradle-plugins - id("com.github.kt3k.coveralls") version "2.12.0" // https://plugins.gradle.org/plugin/com.github.kt3k.coveralls - id("org.javamodularity.moduleplugin") version "1.8.12" // https://plugins.gradle.org/plugin/org.javamodularity.moduleplugin + `creek-common-convention` apply false + `creek-module-convention` apply false + `creek-coverage-convention` + `creek-publishing-convention` apply false + `creek-sonatype-publishing-convention` + id("pl.allegro.tech.build.axion-release") version "1.14.2" // https://plugins.gradle.org/plugin/pl.allegro.tech.build.axion-release } project.version = scmVersion.version -allprojects { - apply(plugin = "idea") - apply(plugin = "java") - apply(plugin = "checkstyle") - apply(plugin = "com.diffplug.spotless") - apply(plugin = "com.github.spotbugs") - apply(plugin = "org.javamodularity.moduleplugin") - - group = "org.creekservice" - - java { - withSourcesJar() - - modularity.inferModulePath.set(false) - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - - repositories { - mavenCentral() - - maven { - url = uri("https://maven.pkg.github.com/creek-service/*") - credentials { - username = "Creek-Bot-Token" - password = "\u0067hp_LtyvXrQZen3WlKenUhv21Mg6NG38jn0AO2YH" - } - } - } -} - subprojects { - apply(plugin = "maven-publish") + project.version = project.parent?.version!! + + apply(plugin = "creek-common-convention") + apply(plugin = "creek-module-convention") if (name.startsWith("test-")) { tasks.javadoc { onlyIf { false } } + } else { + apply(plugin = "creek-publishing-convention") } if (name != "test-java-eight-extension" @@ -55,12 +29,6 @@ subprojects { apply(plugin = "jacoco") } - project.version = project.parent?.version!! - - configurations.all { - resolutionStrategy.cacheChangingModulesFor(10, TimeUnit.MINUTES) - } - extra.apply { set("creekVersion", "0.2.0") set("spotBugsVersion", "4.7.3") // https://mvnrepository.com/artifact/com.github.spotbugs/spotbugs-annotations @@ -95,131 +63,6 @@ subprojects { testImplementation("org.apache.logging.log4j:log4j-slf4j2-impl:$log4jVersion") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion") } - - tasks.compileJava { - options.compilerArgs.add("-Xlint:all,-serial,-requires-automatic,-requires-transitive-automatic,-module") - options.compilerArgs.add("-Werror") - } - - tasks.test { - useJUnitPlatform() - setForkEvery(1) - maxParallelForks = 4 - testLogging { - showStandardStreams = true - exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL - showCauses = true - showExceptions = true - showStackTraces = true - } - } - - spotless { - java { - googleJavaFormat("1.12.0").aosp() - indentWithSpaces() - importOrder() - removeUnusedImports() - trimTrailingWhitespace() - endWithNewline() - } - } - - spotbugs { - tasks.spotbugsMain { - reports.create("html") { - required.set(true) - setStylesheet("fancy-hist.xsl") - } - } - tasks.spotbugsTest { - reports.create("html") { - required.set(true) - setStylesheet("fancy-hist.xsl") - } - } - } - - tasks.withType().configureEach{ - dependsOn(tasks.test) - } - - tasks.jar { - archiveBaseName.set("${rootProject.name}-${project.name}") - } - - tasks.register("format") { - dependsOn("spotlessCheck", "spotlessApply") - } - - tasks.register("static") { - dependsOn("checkstyleMain", "checkstyleTest", "spotbugsMain", "spotbugsTest") - } - - if (!name.startsWith("test-")) { - publishing { - repositories { - maven { - name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/creek-service/${rootProject.name}") - credentials { - username = System.getenv("GITHUB_ACTOR") - password = System.getenv("GITHUB_TOKEN") - } - } - } - publications { - create("maven") { - from(components["java"]) - artifactId = "${rootProject.name}-${project.name}" - - pom { - url.set("https://github.com/creek-service/${rootProject.name}.git") - } - } - } - } - } -} - -val coverage = tasks.register("coverage") { - group = "coverage" - description = "Generates an aggregate code coverage report from all subprojects" - - val coverageReportTask = this - - // If a subproject applies the 'jacoco' plugin, add the result it to the report - subprojects { - val subproject = this - subproject.plugins.withType().configureEach { - subproject.tasks.matching({ it.extensions.findByType() != null }).configureEach { - sourceSets(subproject.sourceSets.main.get()) - executionData(files(subproject.tasks.withType()).filter { it.exists() && it.name.endsWith(".exec") }) - } - - subproject.tasks.matching({ it.extensions.findByType() != null }).forEach { - coverageReportTask.dependsOn(it) - } - } - } - - reports { - xml.required.set(true) - html.required.set(true) - } -} - -coveralls { - sourceDirs = subprojects.flatMap{it.sourceSets.main.get().allSource.srcDirs}.map{it.toString()} - jacocoReportPath = "$buildDir/reports/jacoco/coverage/coverage.xml" -} - -tasks.coveralls { - group = "coverage" - description = "Uploads the aggregated coverage report to Coveralls" - - dependsOn(coverage) - onlyIf{System.getenv("CI") != null} } defaultTasks("format", "static", "check") diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..0503470 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,35 @@ +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() + gradlePluginPortal() +} + +val jvmTargetVer = JavaLanguageVersion.of(11) + +java { + toolchain.languageVersion.set(jvmTargetVer) +} + +kotlin { + jvmToolchain { + (this as JavaToolchainSpec).languageVersion.set(jvmTargetVer) + } +} + +tasks.withType().configureEach { + kotlinOptions { + jvmTarget = "$jvmTargetVer" + } +} + +dependencies { + implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.13") // https://plugins.gradle.org/plugin/com.github.spotbugs + implementation("com.diffplug.spotless:spotless-plugin-gradle:6.11.0") // https://plugins.gradle.org/plugin/com.diffplug.spotless + implementation("gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.0") // https://plugins.gradle.org/plugin/com.github.kt3k.coveralls + implementation("org.javamodularity:moduleplugin:1.8.12") // https://plugins.gradle.org/plugin/org.javamodularity.moduleplugin + implementation("io.github.gradle-nexus:publish-plugin:1.1.0") // https://plugins.gradle.org/plugin/io.github.gradle-nexus.publish-plugin + implementation("com.gradle.publish:plugin-publish-plugin:1.0.0") // https://plugins.gradle.org/plugin/com.gradle.plugin-publish +} \ No newline at end of file diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 0000000..e69de29 diff --git a/buildSrc/src/main/kotlin/creek-common-convention.gradle.kts b/buildSrc/src/main/kotlin/creek-common-convention.gradle.kts new file mode 100644 index 0000000..cdc3de0 --- /dev/null +++ b/buildSrc/src/main/kotlin/creek-common-convention.gradle.kts @@ -0,0 +1,117 @@ +/* + * Copyright 2022 Creek Contributors (https://github.com/creek-service) + * + * 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 + * + * http://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. + */ + +/** + * Standard configuration of Creek projects + * + *

Apply to all java modules, usually excluding the root project in multi-module sets. + */ + +plugins { + java + checkstyle + id("com.github.spotbugs") + id("com.diffplug.spotless") +} + +group = "org.creekservice" + +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + +repositories { + mavenCentral() + + maven { + url = uri("https://maven.pkg.github.com/creek-service/*") + credentials { + username = "Creek-Bot-Token" + password = "\u0067hp_LtyvXrQZen3WlKenUhv21Mg6NG38jn0AO2YH" + } + } +} + +configurations.all { + // Reduce chance of build servers running into compilation issues due to stale snapshots: + resolutionStrategy.cacheChangingModulesFor(15, TimeUnit.MINUTES) +} + +tasks.compileJava { + options.compilerArgs.add("-Xlint:all,-serial,-requires-automatic,-requires-transitive-automatic,-module") + options.compilerArgs.add("-Werror") +} + +tasks.test { + useJUnitPlatform() + setForkEvery(1) + maxParallelForks = 4 + testLogging { + showStandardStreams = true + exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL + showCauses = true + showExceptions = true + showStackTraces = true + } +} + +spotless { + java { + googleJavaFormat("1.12.0").aosp() + indentWithSpaces() + importOrder() + removeUnusedImports() + trimTrailingWhitespace() + endWithNewline() + } +} + +spotbugs { + tasks.spotbugsMain { + reports.create("html") { + required.set(true) + setStylesheet("fancy-hist.xsl") + } + } + tasks.spotbugsTest { + reports.create("html") { + required.set(true) + setStylesheet("fancy-hist.xsl") + } + } +} + +if (rootProject.name != project.name) { + tasks.jar { + archiveBaseName.set("${rootProject.name}-${project.name}") + } +} + +tasks.register("format") { + group = "creek" + description = "Format the code" + + dependsOn("spotlessCheck", "spotlessApply") +} + +tasks.register("static") { + group = "creek" + description = "Run static code analysis" + + dependsOn("checkstyleMain", "checkstyleTest", "spotbugsMain", "spotbugsTest") +} + diff --git a/buildSrc/src/main/kotlin/creek-coverage-convention.gradle.kts b/buildSrc/src/main/kotlin/creek-coverage-convention.gradle.kts new file mode 100644 index 0000000..89da547 --- /dev/null +++ b/buildSrc/src/main/kotlin/creek-coverage-convention.gradle.kts @@ -0,0 +1,74 @@ +/* + * Copyright 2022 Creek Contributors (https://github.com/creek-service) + * + * 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 + * + * http://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. + */ + +/** + * Standard coverage configuration of Creek projects, utilising Jacoco and Coveralls.io + * + *

Apply to root project only + */ + +plugins { + java + jacoco + id("com.github.kt3k.coveralls") +} + +repositories { + mavenCentral() +} + +allprojects { + apply(plugin = "java") + + tasks.withType().configureEach{ + dependsOn(tasks.test) + } +} + +val coverage = tasks.register("coverage") { + group = "creek" + description = "Generates an aggregate code coverage report" + + val coverageReportTask = this + + allprojects { + val proj = this + // Roll results of each (test) task that has Jacoco extension, i.e. plugin applied, into the main coverage task + proj.tasks.matching { it.extensions.findByType() != null && it != coverageReportTask }.forEach { + coverageReportTask.sourceSets(proj.sourceSets.main.get()) + coverageReportTask.executionData(files(proj.tasks.withType()).filter { it.exists() && it.name.endsWith(".exec") }) + coverageReportTask.dependsOn(it) + } + } + + reports { + xml.required.set(true) + html.required.set(true) + } +} + +coveralls { + sourceDirs = allprojects.flatMap{it.sourceSets.main.get().allSource.srcDirs}.map{it.toString()} + jacocoReportPath = "$buildDir/reports/jacoco/coverage/coverage.xml" +} + +tasks.coveralls { + group = "creek" + description = "Uploads the aggregated coverage report to Coveralls" + + dependsOn(coverage) + onlyIf{System.getenv("CI") != null} +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/creek-module-convention.gradle.kts b/buildSrc/src/main/kotlin/creek-module-convention.gradle.kts new file mode 100644 index 0000000..55b21e4 --- /dev/null +++ b/buildSrc/src/main/kotlin/creek-module-convention.gradle.kts @@ -0,0 +1,30 @@ +/* + * Copyright 2022 Creek Contributors (https://github.com/creek-service) + * + * 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 + * + * http://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. + */ + +/** + * Standard configuration of Java Module Platform System, a.k.a. Java 9 modules. + * + *

Apply to all modules that publish JPMS modules. + */ + +plugins { + java + id("org.javamodularity.moduleplugin") +} + +java { + modularity.inferModulePath.set(false) +} diff --git a/buildSrc/src/main/kotlin/creek-plugin-publishing-convention.gradle.kts b/buildSrc/src/main/kotlin/creek-plugin-publishing-convention.gradle.kts new file mode 100644 index 0000000..921ed95 --- /dev/null +++ b/buildSrc/src/main/kotlin/creek-plugin-publishing-convention.gradle.kts @@ -0,0 +1,144 @@ +/* + * Copyright 2022 Creek Contributors (https://github.com/creek-service) + * + * 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 + * + * http://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. + */ + +/** + * Configuration for Creek Gradle plugin publishing. + * + *

Apply this plugin to any module publishing a Gradle plugin. + * + *

Do NOT ally the `creek-publishing-convention`. + */ + +plugins { + java + signing + `maven-publish` + `java-gradle-plugin` + id("com.gradle.plugin-publish") +} + +java { + withSourcesJar() + withJavadocJar() +} + +val prependRootName = rootProject.name != project.name + +pluginBundle { + website = "https://www.creekservie.org" + vcsUrl = "https://github.com/creek-service/${rootProject.name}" + + tags = listOf("creek", "creekservice", "microservice", "docker", "containers") +} + +if (prependRootName) { + tasks.jar { + archiveBaseName.set("${rootProject.name}-${project.name}") + } +} + +tasks.javadoc { + if (JavaVersion.current().isJava9Compatible) { + (options as StandardJavadocDocletOptions).apply { + addBooleanOption("html5", true) + // Why -quite? See: https://github.com/gradle/gradle/issues/2354 + addStringOption("Xwerror", "-quiet") + } + } +} + +tasks.jar { + manifest { + if (prependRootName) { + attributes("Automatic-Module-Name" to "${rootProject.name}-${project.name}") + } else { + attributes("Automatic-Module-Name" to project.name) + } + } +} + +publishing { + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/creek-service/${rootProject.name}") + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + } + + publications.withType().configureEach { + + if (prependRootName) { + artifactId = "${rootProject.name}-${project.name}" + } + + pom { + name.set("${project.group}:${artifactId}") + + if (prependRootName) { + description.set("${rootProject.name.capitalize()} ${project.name} library".replace("-", " ")) + } else { + description.set("${project.name.capitalize()} library".replace("-", " ")) + } + + url.set("https://www.creekservice.org") + + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + + developers { + developer { + name.set("Andy Coates") + email.set("8012398+big-andy-coates@users.noreply.github.com") + organization.set("Creek Service") + organizationUrl.set("https://www.creekservice.org") + } + } + + scm { + connection.set("scm:git:git://github.com/creek-service/${rootProject.name}.git") + developerConnection.set("scm:git:ssh://github.com/creek-service/${rootProject.name}.git") + url.set("https://github.com/creek-service/${rootProject.name}") + } + } + } +} + +/** + * Configure signing of publication artifacts. + * + *

Can be skipped for snapshot builds.

+ * + *

Even snapshot builds will be signed if signing credentials are available. + * See https://central.sonatype.org/publish/publish-gradle/#credentials + */ +signing { + setRequired { + !project.version.toString().endsWith("-SNAPSHOT") + && !project.hasProperty("skipSigning") + } + + if (project.hasProperty("signingKey")) { + useInMemoryPgpKeys(properties["signingKey"].toString(), properties["signingPassword"].toString()) + } +} diff --git a/buildSrc/src/main/kotlin/creek-publishing-convention.gradle.kts b/buildSrc/src/main/kotlin/creek-publishing-convention.gradle.kts new file mode 100644 index 0000000..928bbf3 --- /dev/null +++ b/buildSrc/src/main/kotlin/creek-publishing-convention.gradle.kts @@ -0,0 +1,130 @@ +/* + * Copyright 2022 Creek Contributors (https://github.com/creek-service) + * + * 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 + * + * http://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. + */ + +/** + * Standard configuration for Creek library publishing + * + *

Apply this plugin only to subprojects if in multi-module setup. + * + *

Use `creek-plugin-publishing-convention` for Gradle plugins. + */ + +plugins { + java + signing + `maven-publish` +} + +java { + withSourcesJar() + withJavadocJar() +} + +tasks.javadoc { + if (JavaVersion.current().isJava9Compatible) { + (options as StandardJavadocDocletOptions).apply { + addBooleanOption("html5", true) + // Why -quite? See: https://github.com/gradle/gradle/issues/2354 + addStringOption("Xwerror", "-quiet") + } + } +} + +// Dummy/empty publishPlugins task, to allow consistent build.yml workflow +tasks.register("publishPlugins") { + doLast { + logger.info("No Gradle plugins to publish") + } +} + +publishing { + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/creek-service/${rootProject.name}") + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + } + + publications { + create("mavenJava") { + from(components["java"]) + + val prependRootName = rootProject.name != project.name + if (prependRootName) { + artifactId = "${rootProject.name}-${project.name}" + } + + pom { + name.set("${project.group}:${artifactId}") + + if (prependRootName) { + description.set("${rootProject.name.capitalize()} ${project.name} library".replace("-", " ")) + } else { + description.set("${project.name.capitalize()} library".replace("-", " ")) + } + + url.set("https://www.creekservice.org") + + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + + developers { + developer { + name.set("Andy Coates") + email.set("8012398+big-andy-coates@users.noreply.github.com") + organization.set("Creek Service") + organizationUrl.set("https://www.creekservice.org") + } + } + + scm { + connection.set("scm:git:git://github.com/creek-service/${rootProject.name}.git") + developerConnection.set("scm:git:ssh://github.com/creek-service/${rootProject.name}.git") + url.set("https://github.com/creek-service/${rootProject.name}") + } + } + } + } +} + +/** + * Configure signing of publication artifacts. + * + *

Can be skipped for snapshot builds.

+ * + *

Even snapshot builds will be signed if signing credentials are available. + * See https://central.sonatype.org/publish/publish-gradle/#credentials + */ +signing { + setRequired { + !project.version.toString().endsWith("-SNAPSHOT") + && !project.hasProperty("skipSigning") + } + + if (project.hasProperty("signingKey")) { + useInMemoryPgpKeys(properties["signingKey"].toString(), properties["signingPassword"].toString()) + } + + sign(publishing.publications["mavenJava"]) +} diff --git a/buildSrc/src/main/kotlin/creek-sonatype-publishing-convention.gradle.kts b/buildSrc/src/main/kotlin/creek-sonatype-publishing-convention.gradle.kts new file mode 100644 index 0000000..3539fa4 --- /dev/null +++ b/buildSrc/src/main/kotlin/creek-sonatype-publishing-convention.gradle.kts @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Creek Contributors (https://github.com/creek-service) + * + * 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 + * + * http://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. + */ + +/** + * Standard configuration for Creek library publishing to Maven Central vis SonaType OSSRH + * + * // Apply this plugin only to the root project if in multi-module setup. + */ + +plugins { + id("io.github.gradle-nexus.publish-plugin") +} + +nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + stagingProfileId.set("89a20518f39cd") + + if (project.hasProperty("SONA_USERNAME")) { + username.set(project.property("SONA_USERNAME").toString()) + } + + if (project.hasProperty("SONA_PASSWORD")) { + password.set(project.property("SONA_PASSWORD").toString()) + } + } + } +}