Skip to content

Instantly share code, notes, and snippets.

@bitkill
Last active January 31, 2022 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitkill/52c7bf93ac6bcfbc3d7161a3ce59ed66 to your computer and use it in GitHub Desktop.
Save bitkill/52c7bf93ac6bcfbc3d7161a3ce59ed66 to your computer and use it in GitHub Desktop.
[Gradle lib multimodule] #gradle #lib #github-actions
# location: .github/workflow/tag-publish.yml
name: tag-publish
on:
push:
tags: [ '*' ]
permissions:
id-token: write
contents: read
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build publish
env:
GITHUB_USERNAME: ${{ env.GITHUB_ACTOR }}
GITHUB_TOKEN: ${{ github.token }}
- uses: actions/upload-artifact@v2 # upload gradle reports
if: success() || failure()
with:
name: report
retention-days: 14
path: build/reports/
plugins {
id("fr.brouillard.oss.gradle.jgitver") version "0.9.1"
}
subprojects {
group = "org.ruifernandes.some.lib"
apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "jacoco")
apply(plugin = "fr.brouillard.oss.gradle.jgitver")
configure<PublishingExtension> {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/bitkill/some-lib")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
}
publications {
register<MavenPublication>("gpr") {
from(components["java"])
}
}
}
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_17
withJavadocJar()
withSourcesJar()
}
repositories {
mavenCentral()
mavenLocal()
}
}
gradle init --type java-library
// location: lib/build.gradle.kts
plugins {
// add specific plugins here
}
val lombokVersion = "1.18.22"
dependencies {
// Lombok
compileOnly("org.projectlombok:lombok:${lombokVersion}")
annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
// Mapping library
implementation("org.mapstruct:mapstruct:1.4.2.Final")
// Use JUnit Jupiter for testing.
testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
// Allow lombok in tests
testCompileOnly("org.projectlombok:lombok:${lombokVersion}")
testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")
}
tasks.test {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
rootProject.name = "some-lib"
include("lib")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment