Skip to content

Instantly share code, notes, and snippets.

@nwillc
Created January 28, 2018 15:55
Show Gist options
  • Save nwillc/a8c864c35a460c33ee98c7a4e95dfe56 to your computer and use it in GitHub Desktop.
Save nwillc/a8c864c35a460c33ee98c7a4e95dfe56 to your computer and use it in GitHub Desktop.
Gradle snippet to build jdk9 module
plugins {
id 'java-library'
}
repositories {
jcenter()
}
ext.moduleName = 'com.github.nwillc.fluentsee'
version = '1.0.0'
dependencies {
implementation // dependencies
testImplementation // test dependencies
}
compileJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = ['--module-path', classpath.asPath]
classpath = files()
}
}
compileTestJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--patch-module', "$moduleName=" + files(sourceSets.test.java.srcDirs).asPath,
]
classpath = files()
}
}
test {
inputs.property("moduleName", moduleName)
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'ALL-MODULE-PATH',
'--patch-module', "$moduleName=" + files(sourceSets.test.java.outputDir,
sourceSets.test.resources.srcDirs).asPath]
classpath = files()
}
}
jar {
manifest {
attributes 'Main-Class': // main class
}
}
task copyMainResources(type: Copy) {
from sourceSets.main.resources
into "$buildDir/classes/java/main"
}
task mJar(type: Exec) {
dependsOn build, copyMainResources
commandLine 'jar', '--create',
'--file', "$buildDir/libs/${project.name}-module-${project.version}.jar",
'--main-class', 'com.github.nwillc.fluentsee.Main',
'--module-version', project.version,
'-C', 'build/classes/java/main',
'.'
}
task module(type: Copy) {
from "$buildDir/libs/${project.name}-module-${project.version}.jar"
from configurations.runtimeClasspath.incoming.files
into "$buildDir/mods"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment