diff --git a/README.md b/README.md index 182ec88..45f7147 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/convention-plugin/build.gradle.kts b/convention-plugin/build.gradle.kts index 4cb3900..0207cd3 100644 --- a/convention-plugin/build.gradle.kts +++ b/convention-plugin/build.gradle.kts @@ -18,9 +18,14 @@ 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()) @@ -28,6 +33,13 @@ dependencies { 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" diff --git a/convention-plugin/src/main/kotlin/org/metaborg/convention/SettingsConventionExtension.kt b/convention-plugin/src/main/kotlin/org/metaborg/convention/SettingsConventionExtension.kt new file mode 100644 index 0000000..d58112f --- /dev/null +++ b/convention-plugin/src/main/kotlin/org/metaborg/convention/SettingsConventionExtension.kt @@ -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() { + + } +} \ No newline at end of file diff --git a/convention-plugin/src/main/kotlin/org/metaborg/convention/SettingsConventionPlugin.kt b/convention-plugin/src/main/kotlin/org/metaborg/convention/SettingsConventionPlugin.kt new file mode 100644 index 0000000..59bf174 --- /dev/null +++ b/convention-plugin/src/main/kotlin/org/metaborg/convention/SettingsConventionPlugin.kt @@ -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 { + + private val catalogVersion = "0.3.6" + + @Suppress("UnstableApiUsage") + override fun apply(settings: Settings): Unit = with(settings) { + // Add the configuration extension + val extension = extensions.create("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) + } + } + } + } +} \ No newline at end of file diff --git a/example/settings.gradle.kts b/example/settings.gradle.kts index a2be9f5..0771fb7 100644 --- a/example/settings.gradle.kts +++ b/example/settings.gradle.kts @@ -4,3 +4,6 @@ pluginManagement { includeBuild("../convention-plugin") } +plugins { + id("org.metaborg.convention.settings") +} \ No newline at end of file