Skip to content

Commit

Permalink
Make separate plugin for configuring RADAR projects
Browse files Browse the repository at this point in the history
  • Loading branch information
blootsvoets committed Mar 22, 2023
1 parent deb0dd9 commit a5b2d19
Show file tree
Hide file tree
Showing 70 changed files with 753 additions and 488 deletions.
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
# Change these settings to your own preference
indent_style = space
indent_size = 4

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{kt,kts}]
ktlint_standard_no-wildcard-imports = disabled

[*.md]
trim_trailing_whitespace = false

[*.{json,yaml,yml}]
indent_style = space
indent_size = 2
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ jobs:
# Gradle check
- name: Check
run: ./gradlew check

- name: Check version
run:
projectVersion=$(./gradlew properties | grep '^version:.*$')
pluginVersion=$(./gradlew :radar-commons-plugin:properties | grep '^version:.*$')
if [ "$projectVersion" != "$pluginVersion" ]; then
echo "Project version $projectVersion does not match plugin version $pluginVersion"
exit 1
fi
15 changes: 11 additions & 4 deletions .github/workflows/publish_snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Has SNAPSHOT version
id: is-snapshot
run: grep "version = '.*-SNAPSHOT'" build.gradle

- uses: actions/setup-java@v3
with:
distribution: temurin
Expand All @@ -29,6 +25,9 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Has SNAPSHOT version
run: ./gradlew properties | grep '^version:.*-SNAPSHOT$'

- name: Install gpg secret key
run: |
cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import
Expand All @@ -39,3 +38,11 @@ jobs:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
run: ./gradlew -Psigning.gnupg.keyName=CBEF2CF0 -Psigning.gnupg.executable=gpg -Psigning.gnupg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} publish

- name: Plugin has SNAPSHOT version
run: ./gradlew :radar-commons-plugin:properties | grep '^version:.*-SNAPSHOT$'

- name: Publish gradle plugin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew :radar-commons-plugin:publish
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Check version
run:
projectVersion=$(./gradlew properties | grep '^version:.*$')
pluginVersion=$(./gradlew :radar-commons-plugin:properties | grep '^version:.*$')
if [ "$projectVersion" != "$pluginVersion" ]; then
echo "Project version $projectVersion does not match plugin version $pluginVersion"
exit 1
fi

# Compile code
- name: Compile code
run: ./gradlew assemble
Expand All @@ -44,3 +53,8 @@ jobs:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
run: ./gradlew -Psigning.gnupg.keyName=CBEF2CF0 -Psigning.gnupg.executable=gpg -Psigning.gnupg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} publish closeAndReleaseSonatypeStagingRepository

- name: Publish gradle plugin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew :radar-commons-plugin:publish
21 changes: 17 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.radarbase.gradle.plugin.radarKotlin
import org.radarbase.gradle.plugin.radarPublishing
import org.radarbase.gradle.plugin.radarRootProject

plugins {
kotlin("plugin.serialization") version Versions.Plugins.kotlinSerialization apply false
id("com.github.davidmc24.gradle.plugin.avro") version Versions.Plugins.avro apply false
id("org.radarbase.radar-root-project")
id("org.radarbase.radar-dependency-management")
}

val githubRepoName = "RADAR-base/radar-commons"
val githubUrl = "https://github.com/$githubRepoName"

apply<RootConventionsPlugin>()
apply<DependencyUpdatesPlugin>()
radarRootProject {
projectVersion.set(Versions.project)
}

subprojects {
// Apply the plugins
apply<KotlinConventionsPlugin>()
apply<RadarPublishingPlugin>()
apply(plugin = "org.radarbase.radar-kotlin")
apply(plugin = "org.radarbase.radar-publishing")

dependencies {
configurations["testImplementation"]("org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.coroutines}")
Expand All @@ -51,6 +58,12 @@ subprojects {
}
}

radarKotlin {
javaVersion.set(Versions.java)
kotlinVersion.set(Versions.Plugins.kotlin)
junitVersion.set(Versions.junit)
}

//---------------------------------------------------------------------------//
// Style checking //
//---------------------------------------------------------------------------//
Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ dependencies {
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.8.10")
implementation("com.github.ben-manes:gradle-versions-plugin:0.46.0")
implementation("io.github.gradle-nexus:publish-plugin:1.3.0")
implementation("org.jlleitschuh.gradle:ktlint-gradle:11.3.1")
}
61 changes: 0 additions & 61 deletions buildSrc/src/main/kotlin/KotlinConventionsPlugin.kt

This file was deleted.

7 changes: 3 additions & 4 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
object Versions {
const val project = "0.16.0-SNAPSHOT"
const val wrapper = "8.0.2"

object Plugins {
const val kotlinSerialization = "1.8.10"
const val kotlin = "1.8.10"
const val kotlinSerialization = kotlin
const val avro = "1.6.0"
}

const val java = "11"
const val java = 11
const val slf4j = "2.0.7"
const val confluent = "7.3.2"
const val kafka = "7.3.2-ce"
Expand All @@ -19,7 +19,6 @@ object Versions {
const val mockitoKotlin = "4.1.0"
const val hamcrest = "2.2"
const val radarSchemas = "0.8.2"
const val orgJson = "20220924"
const val opencsv = "5.7.1"
const val ktor = "2.2.4"
const val coroutines = "1.6.4"
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

projectVersion=0.16.0-SNAPSHOT
57 changes: 57 additions & 0 deletions radar-commons-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
plugins {
`kotlin-dsl`
`java-gradle-plugin`
kotlin("jvm") version "1.8.10"
`maven-publish`
}

version = "0.16.0-SNAPSHOT"
group = "org.radarbase"
description = "RADAR common Gradle plugins"

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.8.10")
implementation("com.github.ben-manes:gradle-versions-plugin:0.46.0")
implementation("io.github.gradle-nexus:publish-plugin:1.3.0")
implementation("org.jlleitschuh.gradle:ktlint-gradle:11.3.1")
}

gradlePlugin {
plugins {
create("radarRootProject") {
id = "org.radarbase.radar-root-project"
implementationClass = "org.radarbase.gradle.plugin.RadarRootProjectPlugin"
}
create("radarPublishing") {
id = "org.radarbase.radar-publishing"
implementationClass = "org.radarbase.gradle.plugin.RadarPublishingPlugin"
}
create("radarDependencyManagement") {
id = "org.radarbase.radar-dependency-management"
implementationClass = "org.radarbase.gradle.plugin.RadarDependencyManagementPlugin"
}
create("radarKotlin") {
id = "org.radarbase.radar-kotlin"
implementationClass = "org.radarbase.gradle.plugin.RadarKotlinPlugin"
}
}
}

publishing {
repositories {
maven {
name = "GitHubPackages"
setUrl("https://maven.pkg.github.com/radar-base/radar-commons")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package org.radarbase.gradle.plugin

import com.github.benmanes.gradle.versions.VersionsPlugin
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.gradle.api.provider.Property
import org.gradle.kotlin.dsl.create
import com.github.benmanes.gradle.versions.VersionsPlugin
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.create

fun Project.dependencyUpdates(configure: DependencyUpdatesPluginExtension.() -> Unit) {
configure<DependencyUpdatesPluginExtension>(configure)
fun Project.radarDependencyManagement(configure: RadarDependencyManagementExtension.() -> Unit) {
configure(configure)
}

interface DependencyUpdatesPluginExtension {
interface RadarDependencyManagementExtension {
val regex: Property<String>
val minorUpdatesOnly: Property<Boolean>
}

class DependencyUpdatesPlugin : Plugin<Project> {
class RadarDependencyManagementPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = with(project) {
val extension = extensions.create<DependencyUpdatesPluginExtension>("radarDependencies").apply {
val extension = extensions.create<RadarDependencyManagementExtension>("radarDependencies").apply {
regex.convention("(^[0-9,.v-]+(-r)?|RELEASE|FINAL|GA|-CE)$")
minorUpdatesOnly.convention(false)
}
Expand Down
Loading

0 comments on commit a5b2d19

Please sign in to comment.