Skip to content

Commit

Permalink
Setup Gradle plugins for correct snapshot publication (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp94831 authored Feb 29, 2024
1 parent 8905e8d commit bceceff
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
build-and-publish:
name: Java Gradle
uses: bakdata/ci-templates/.github/workflows/java-gradle-plugin.yaml@1.41.0
uses: bakdata/ci-templates/.github/workflows/java-gradle-plugin.yaml@1.42.0
secrets:
sonar-token: ${{ secrets.SONARCLOUD_TOKEN }}
sonar-organization: ${{ secrets.SONARCLOUD_ORGANIZATION }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
jobs:
java-gradle-release:
name: Java Gradle
uses: bakdata/ci-templates/.github/workflows/java-gradle-release.yaml@1.41.0
uses: bakdata/ci-templates/.github/workflows/java-gradle-release.yaml@1.42.0
with:
release-type: "${{ inputs.release-type }}"

Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,24 @@ A collection of small gradle plugin, mostly focused on deployment.
**Sonar** Some defaults for easy integration of sonar on multi-module projects
**Sonatype** is used for uploading to sonatype repos and ultimately publish to Maven Central

## Development

Snapshot versions of these plugins are published to Sonatype.
You can use them in your project by adding the following snippet to your `build.gradle.kts`

```
buildscript {
repositories {
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots")
}
}
dependencies {
classpath("com.bakdata.gradle:sonar:0.0.1-SNAPSHOT")
classpath("com.bakdata.gradle:sonatype:0.0.1-SNAPSHOT")
}
}
apply(plugin = "com.bakdata.sonar")
apply(plugin = "com.bakdata.sonatype")
```
59 changes: 28 additions & 31 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,39 @@ subprojects {
targetCompatibility = JavaVersion.VERSION_11
}

dependencies {
"testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:5.3.0")
"testImplementation"("org.junit.jupiter:junit-jupiter-api:5.3.0")
"testImplementation"("org.assertj", "assertj-core", "3.11.1")
"testImplementation"("org.junit-pioneer", "junit-pioneer", "0.3.0")
apply(plugin = "java-gradle-plugin")

// config for gradle plugin portal doesn't support snapshot, so we add config only if release version
if (!version.toString().endsWith("-SNAPSHOT")) {
apply(plugin = "com.gradle.plugin-publish")
}
}

// config for gradle plugin portal
// doesn't support snapshot, so we add config only if release version
if (!version.toString().endsWith("-SNAPSHOT")) {
subprojects.forEach { project ->
with(project) {
// com.gradle.plugin-publish depends on java-gradle-plugin, but it screws a bit this project
apply(plugin = "java-gradle-plugin")
apply(plugin = "com.gradle.plugin-publish")
project.afterEvaluate {
// java-gradle-plugin requires this block, but we already added the definitions in META-INF for unit testing...
configure<GradlePluginDevelopmentExtension> {
plugins {
create("${project.name.capitalize()}Plugin") {
id = "com.bakdata.${project.name}"
implementationClass = "com.bakdata.gradle.${project.name.capitalize()}Plugin"
description = project.description
displayName = "Bakdata $name plugin"
}
}
}
// actual block of plugin portal config, need to be done on each subproject as the plugin does not support multi-module projects yet...
configure<com.gradle.publish.PluginBundleExtension> {
website = "https://github.com/bakdata/gradle-plugins"
vcsUrl = "https://github.com/bakdata/gradle-plugins"
tags = listOf("bakdata", name)
// description is only ready after evaluation
afterEvaluate {
configure<GradlePluginDevelopmentExtension> {
plugins {
create("${project.name.capitalize()}Plugin") {
id = "com.bakdata.${project.name}"
implementationClass = "com.bakdata.gradle.${project.name.capitalize()}Plugin"
description = project.description
displayName = "Bakdata $name plugin"
}
}
}

extensions.findByType(com.gradle.publish.PluginBundleExtension::class)?.apply {
// actual block of plugin portal config, need to be done on each subproject as the plugin does not support multi-module projects yet...
website = "https://github.com/bakdata/gradle-plugins"
vcsUrl = "https://github.com/bakdata/gradle-plugins"
tags = listOf("bakdata", name)
}
}

dependencies {
"testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:5.3.0")
"testImplementation"("org.junit.jupiter:junit-jupiter-api:5.3.0")
"testImplementation"("org.assertj", "assertj-core", "3.11.1")
"testImplementation"("org.junit-pioneer", "junit-pioneer", "0.3.0")
}
}

Expand Down

0 comments on commit bceceff

Please sign in to comment.