Skip to content

Commit

Permalink
Add org.metaborg.convention.settings plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Virtlink committed Jul 9, 2024
1 parent 628a7cc commit 2a93f91
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 5 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ The Metaborg Gradle convention and development plugins.

[![Documentation][documentation-button]][documentation]

| Artifact | Latest Release |
|-----------------------------------------|---------------------------------------------------------------------------|
| `org.metaborg.convention.java` | [![org.metaborg.convention.java][convention-java-badge]][convention-java] |
| Artifact | Latest Release |
|-----------------------------------------|------------------------------------------------------------------------------------------------------|
| `org.metaborg.convention.settings` | [![org.metaborg.convention.settings][convention-settings-badge]][convention-settings] |
| `org.metaborg.convention.java` | [![org.metaborg.convention.java][convention-java-badge]][convention-java] |
| `org.metaborg.convention.maven-publish` | [![org.metaborg.convention.maven-publish][convention-maven-publish-badge]][convention-maven-publish] |
| `org.metaborg.convention.root-project` | [![org.metaborg.convention.root-project][convention-root-project-badge]][convention-root-project] |
| `org.metaborg.convention.root-project` | [![org.metaborg.convention.root-project][convention-root-project-badge]][convention-root-project] |



## Gradle Convention
The `org.metaborg.convention` plugins applies any conventional configuration to Metaborg projects. It has the following plugins:
The `org.metaborg.convention` plugins applies any conventional configuration to Metaborg build and projects. It has the following plugins:

- `org.metaborg.convention.settings`: Configures a build (in `settings.gradle.kts`) by applying a version catalog and the Develocity plugin.
- `org.metaborg.convention.java`: Configures a project as a Java project (library or application).
- `org.metaborg.convention.maven-publish`: Configures the Maven publications for a project.
- `org.metaborg.convention.root-project`: Configures the root project of a Gradle multi-project build.
Expand All @@ -45,6 +47,8 @@ https://img.shields.io/github/actions/workflow/status/metaborg/metaborg-gradle/b
[documentation]: https://spoofax.dev/metaborg-gradle/
[documentation-button]: https://img.shields.io/badge/Documentation-blue?style=for-the-badge&logo=googledocs&logoColor=white

[convention-settings-badge]: https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fartifacts.metaborg.org%2Fcontent%2Frepositories%2Freleases%2Forg%2Fmetaborg%2Fconvention%2Fsettings%2Forg.metaborg.convention.settings.gradle.plugin%2Fmaven-metadata.xml
[convention-settings]: https://artifacts.metaborg.org/#nexus-search;gav~org.metaborg.convention.settings~org.metaborg.convention.settings.gradle.plugin~~~
[convention-java-badge]: https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fartifacts.metaborg.org%2Fcontent%2Frepositories%2Freleases%2Forg%2Fmetaborg%2Fconvention%2Fjava%2Forg.metaborg.convention.java.gradle.plugin%2Fmaven-metadata.xml
[convention-java]: https://artifacts.metaborg.org/#nexus-search;gav~org.metaborg.convention.java~org.metaborg.convention.java.gradle.plugin~~~
[convention-maven-publish-badge]: https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fartifacts.metaborg.org%2Fcontent%2Frepositories%2Freleases%2Forg%2Fmetaborg%2Fconvention%2Fmaven-publish%2Forg.metaborg.convention.maven-publish.gradle.plugin%2Fmaven-metadata.xml
Expand Down
12 changes: 12 additions & 0 deletions convention-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,28 @@ extra["isCI"] = !System.getenv("CI").isNullOrEmpty()

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation(gradleApi())
implementation(gradleKotlinDsl())
api(libs.gradle.develocityPlugin)

testImplementation(libs.kotest)
testImplementation(libs.kotest.assertions)
testImplementation(gradleTestKit())
}

gradlePlugin {
plugins {
// Settings plugins
create("convention.settings") {
id = "org.metaborg.convention.settings"
implementationClass = "org.metaborg.convention.SettingsConventionPlugin"
}

// Project plugins
create("convention.java") {
id = "org.metaborg.convention.java"
implementationClass = "org.metaborg.convention.JavaConventionPlugin"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.metaborg.convention

/** Configuration for the settings build convention. */
interface SettingsConventionExtension {

/**
* Sets the convention (default values) for the configuration extension.
*/
fun setConvention() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.metaborg.convention

import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import org.gradle.api.Plugin
import org.gradle.api.initialization.Settings
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.maven

/**
* Configures a Gradle build.
*/
@Suppress("unused")
class SettingsConventionPlugin: Plugin<Settings> {

private val catalogVersion = "0.3.6"

@Suppress("UnstableApiUsage")
override fun apply(settings: Settings): Unit = with(settings) {
// Add the configuration extension
val extension = extensions.create<SettingsConventionExtension>("settingsConvention")
extension.setConvention()

// This allows us to use plugins from Metaborg Artifacts
pluginManagement {
repositories {
maven(url = "https://artifacts.metaborg.org/content/groups/public/")
}
}

// This allows us to use the catalog in dependencies
dependencyResolutionManagement {
repositories {
maven(url = "https://artifacts.metaborg.org/content/groups/public/")
}
versionCatalogs {
create("libs") {
from("org.metaborg.spoofax3:catalog:$catalogVersion")
}
}
}

// Apply and configure the Develocity plugin
plugins.apply("com.gradle.develocity")
extensions.configure(DevelocityConfiguration::class.java) {
val isCI = System.getenv("CI").isNullOrEmpty()
buildScan {
termsOfUseUrl.set("https://gradle.com/help/legal-terms-of-use")
termsOfUseAgree.set("yes")
publishing.onlyIf { isCI }
if (isCI) tag("CI")
capture {
fileFingerprints.set(true)
}
}
}
}
}
3 changes: 3 additions & 0 deletions example/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ pluginManagement {
includeBuild("../convention-plugin")
}

plugins {
id("org.metaborg.convention.settings")
}

0 comments on commit 2a93f91

Please sign in to comment.