Skip to content

Commit

Permalink
Add JavaPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Virtlink committed May 29, 2024
1 parent 3fcc445 commit b6589e1
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
4 changes: 2 additions & 2 deletions convention-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ dependencies {
gradlePlugin {
plugins {
create("gradle-convention.java") {
id = "org.metaborg.gradle-convention.java"
implementationClass = "org.metaborg.gradleconvention.JavaPlugin"
id = "org.metaborg.gradle.java-convention"
implementationClass = "org.metaborg.gradle.JavaConventionPlugin"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.metaborg.gradle

import org.gradle.api.provider.Property
import org.gradle.jvm.toolchain.JavaLanguageVersion

/** Configuration for the Java convention. */
interface JavaConventionExtension {
/** The Java version to compile to. */
val javaVersion: Property<JavaLanguageVersion>

/**
* Sets the convention (default values) for the configuration extension.
*/
fun setConvention() {
javaVersion.convention(JavaLanguageVersion.of(11))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.metaborg.gradle

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.api.tasks.testing.Test
import org.gradle.external.javadoc.CoreJavadocOptions
import org.gradle.kotlin.dsl.*

/**
* Configures a Gradle project that builds a Java library or application.
*
* Also apply the `java`, `java-library` or `application` plugin to the project.
*/
@Suppress("unused")
class JavaConventionPlugin: Plugin<Project> {
override fun apply(project: Project): Unit = with(project) {
// Apply the configuration extension
val extension = extensions.create<JavaConventionExtension>("javaConvention")
extension.setConvention()

repositories {
// Maven Artifacts repository
maven(url = "https://artifacts.metaborg.org/content/groups/public/")
// Repository for other packages
mavenCentral()
}

plugins.withType<JavaPlugin> {
tasks.withType<Test> {
// Support any JUnit 5 compatible test runner
useJUnitPlatform()
}

configure<JavaPluginExtension> {
// Compile to a specific Java version
toolchain.languageVersion.set(extension.javaVersion)
// Generate a sources JAR
withSourcesJar()
// Generate a JavaDoc JAR
withJavadocJar()
}

tasks.withType<JavaCompile> {
// Use UTF-8 encoding by default
options.encoding = "UTF-8"
// Warn for unchecked casts
options.compilerArgs.add("-Xlint:unchecked")
// Show more details when the project uses API that is deprecated
options.compilerArgs.add("-Xlint:deprecation")
// Show more details when the project uses API scheduled for removal
options.compilerArgs.add("-Xlint:removal")
// Silence doclint warnings
options.compilerArgs.add("-Xdoclint:none")
}

tasks.withType<Javadoc> {
options {
this as CoreJavadocOptions
// Use UTF-8 encoding by default
encoding = "UTF-8"
charset("UTF-8")
// Silence doclint warnings
addStringOption("Xdoclint:none", "-quiet")
quiet()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.metaborg.gradle

import org.gradle.api.Plugin
import org.gradle.api.Project

class MavenPublishConventionPlugin: Plugin<Project> {
override fun apply(target: Project) {
// maven-publish plugin
// - Configure maven-publish
// configure SCM (GitHub by default, etc)
// configure owner
// configure name
// configure license (Apache 2.0 by default)
// configure developers
// configure inception year
// configure publish to GitHub packages (by default if SCM = GitHub)
// configure publish to Metaborg Artifacts (by default)
// configure publish to Maven Central (optional)
// - Configure signing (optional)

TODO("Not yet implemented")
}
}

0 comments on commit b6589e1

Please sign in to comment.