-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
convention-plugin/src/main/kotlin/org/metaborg/gradle/JavaConventionExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
convention-plugin/src/main/kotlin/org/metaborg/gradle/JavaConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
convention-plugin/src/main/kotlin/org/metaborg/gradle/MavenPublishConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |