Skip to content

Commit

Permalink
Migrate the build system from Maven to Gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
purejava committed Jan 9, 2025
1 parent f6dc0d9 commit e660938
Show file tree
Hide file tree
Showing 18 changed files with 680 additions and 384 deletions.
18 changes: 1 addition & 17 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
version: 2
updates:
- package-ecosystem: "maven"
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "weekly"
day: "saturday"
time: "06:00"
timezone: "Etc/UTC"
groups:
java-test-dependencies:
patterns:
- "org.junit.jupiter:*"
maven-build-plugins:
patterns:
- "org.apache.maven.plugins:*"
- "org.sonatype.plugins:*"
java-production-dependencies:
patterns:
- "*"
exclude-patterns:
- "org.openjfx:*"
- "org.apache.maven.plugins:*"
- "org.junit.jupiter:*"
- "org.sonatype.plugins:*"

- package-ecosystem: "github-actions"
directory: "/" # even for `.github/workflows`
Expand Down
49 changes: 0 additions & 49 deletions .github/workflows/build_and_release.yml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/codeql-analysis.init.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2020 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
*
* 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.
*/

allprojects {
tasks.withType(JavaCompile).configureEach {
outputs.doNotCacheIf("CodeQL scanning", { true })
}
}
123 changes: 99 additions & 24 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,105 @@ on:
schedule:
- cron: '34 10 * * 4'

permissions: {}

jobs:
analyse:
name: Analyse
CodeQL-Build:
permissions:
actions: read # for github/codeql-action/init to get workflow details
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/analyze to upload SARIF results
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"

strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['java', 'javascript']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: java
- name: Build
run: mvn -B compile
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
- name: Checkout repository
uses: actions/checkout@v4
# Checkout must run before the caching key is computed using the `hashFiles` method

- name: Cache Gradle Modules
uses: actions/cache@v4
with:
path: |
~/.gradle/caches/modules-2/
~/.gradle/caches/build-cache-1/
~/.gradle/caches/signatures/
~/.gradle/caches/keyrings/
key: ${{ runner.os }}-gradle-cache-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
if: ${{ matrix.language == 'java' }}

- name: Disable checksum offloading
# See: https://github.com/actions/virtual-environments/issues/1187#issuecomment-686735760
run: sudo ethtool -K eth0 tx off rx off

# Install and setup JDK 17
- name: Setup JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
tools: latest
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

- name: Compile with Gradle with Build Scan
if: ${{ matrix.language == 'java' && github.repository_owner == 'gradle' }}
run: ./gradlew --init-script .github/workflows/codeql-analysis.init.gradle -DcacheNode=us -S testClasses -Dhttp.keepAlive=false
env:
# Set the DEVELOCITY_ACCESS_KEY so that Gradle Build Scans are generated
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
# Potential stop-gap solution for ReadTimeout issues with the Gradle Build Cache
# https://gradle.slack.com/archives/CHDLT99C6/p1636477584059200
GRADLE_OPTS: -Dhttp.keepAlive=false
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_PRIVATE_KEY }}
ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.GPG_PRIVATE_KEY_ID }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_PASSPHRASE }}
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.NEXUS_PASSWORD }}

- name: Compile with Gradle without Build Scan
if: ${{ matrix.language == 'java' && github.repository_owner != 'gradle' }}
run: ./gradlew --init-script .github/workflows/codeql-analysis.init.gradle -S testClasses

- name: Cleanup Gradle Daemons
run: ./gradlew --stop
if: ${{ matrix.language == 'java' }}

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
config-file: ./.github/codeql/codeql-config.yml

- name: Cleanup Gradle Cache
# Cleans up the Gradle caches before being cached
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
if: ${{ matrix.language == 'java' }}
44 changes: 34 additions & 10 deletions .github/workflows/release_to_maven.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
name: Publish to Maven Central

on:
workflow_dispatch:
inputs:
tag:
description: 'Tag'
required: true
default: '0.0.0'
sonatypeUsername:
description: 'Sonatype username'
type: string
required: true
sonatypePassword:
description: 'Sonatype password'
type: string
required: true

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Maven Central Repository

- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Setup GPG key information
run: |
mkdir -p ~/.gradle ~/.gnupg
echo "signing.gnupg.homeDir=/home/runner/.gnupg" >> ~/.gradle/gradle.properties
echo "signing.gnupg.executable=gpg" >> ~/.gradle/gradle.properties
echo "signing.gnupg.keyName=ABC48776" >> ~/.gradle/gradle.properties
echo "signing.gnupg.passphrase=${GPG_SIGNING_KEY_PW}" >> ~/.gradle/gradle.properties
echo "no-tty" >> ~/.gnupg/gpg.conf >> ~/.gradle/gradle.properties
env:
GPG_SIGNING_KEY_PW: ${{ secrets.GPG_PASSPHRASE }}

- name: Build package
run: ./gradlew clean build

- name: Publish package
run: mvn deploy -B -DskipTests -Psign,deploy-central --no-transfer-progress
run: ./gradlew publishToSonatype closeSonatypeStagingRepository
env:
MAVEN_USERNAME: ${{ secrets.NEXUS_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
SONATYPE_USERNAME: ${{ inputs.sonatypeUsername }}
SONATYPE_PASSWORD: ${{ inputs.sonatypePassword }}
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
.project
.classpath

# Maven #
target/
pom.xml.versionsBackup
# Gradle
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

# IntelliJ Settings Files (https://intellij-support.jetbrains.com/hc/en-us/articles/206544839-How-to-manage-projects-under-Version-Control-Systems) #
.idea/**/workspace.xml
Expand Down
9 changes: 1 addition & 8 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e660938

Please sign in to comment.