Skip to content

Commit

Permalink
java9-modularity#79: clean-up of test-projects + bumped Gradle to 5.3…
Browse files Browse the repository at this point in the history
….1 in SmokeTest
  • Loading branch information
tlinkowski committed Apr 14, 2019
1 parent 227b4f7 commit 95e7a9c
Show file tree
Hide file tree
Showing 36 changed files with 248 additions and 463 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ userHome/
# JEnv Java Version
.java-version

# Gradle wrapper in test projects
/test-project*/gradlew*
/test-project*/gradle/wrapper/*
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@SuppressWarnings("ConstantConditions")
class ModulePluginSmokeTest {

private static final String GRADLE_VERSION = "5.0";
private static final String GRADLE_VERSION = "5.3.1";

private List<File> pluginClasspath;

Expand Down
8 changes: 4 additions & 4 deletions test-project-kotlin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ You can test the locally published plugin by running the following command from

`../gradlew -c local_maven_settings.gradle clean build`

It will use the latest locally published version of the plugin to compile the test project with
It will use the locally published version of the plugin to compile the test project with
modules and run the unit tests.


Internal test project
===

This mode is enabled in `ModulePluginSmokeTest` by passing an extra parameter (`-c smoke_test_settings.gradle`)
that points to `smoke_test_build.gradle.kts` instead of `build.gradle.kts`. It doesn't resolve a plugin jar.
Instead, it relies on the smoke test to make the plugin under development available
This mode is enabled in `ModulePluginSmokeTest` by passing an extra parameter (`-c smoke_test_settings.gradle`).
`smoke_test_settings.gradle` script configures plugin management for `build.gradle.kts` so that the plugin cannot be resolved from
a Gradle plugin repository. Instead, it relies on the smoke test to make the plugin under development available
to the test project by sharing a classpath (using Gradle TestKit).

__CAUTION:__ This approach won't work outside of the smoke test, it will break the build because the plugin jar won't be resolved.
69 changes: 33 additions & 36 deletions test-project-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,56 +1,53 @@
buildscript {
repositories {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("org.javamodularity:moduleplugin:1.+")
}
}
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
val kotlinVersion = "1.3.20"
kotlin("jvm") version kotlinVersion
kotlin("jvm") version "1.3.20" apply false
id("org.javamodularity.moduleplugin") version "1.5.0" apply false
}

repositories {
mavenCentral()
}
subprojects {
repositories {
mavenCentral()
}
apply {
plugin("kotlin")
apply(plugin = "kotlin")
apply(plugin = "org.javamodularity.moduleplugin")

//region https://docs.gradle.org/current/userguide/kotlin_dsl.html#using_kotlin_delegated_properties
val test by tasks.existing(Test::class)
val build by tasks
val javadoc by tasks

val implementation by configurations
val testImplementation by configurations
val testRuntimeOnly by configurations

val jUnitVersion: String by project
//endregion

//region KOTLIN
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
if (!project.hasProperty("INTERNAL_TEST_IN_PROGRESS")) {
apply(plugin = "org.javamodularity.moduleplugin")
dependencies {
implementation(kotlin("stdlib-jdk8"))
}
//endregion

project.version = "1.1.1"

configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}

val test by tasks.getting(Test::class) {
test {
useJUnitPlatform()

testLogging {
events("PASSED", "FAILED", "SKIPPED")
stackTraceFilters = listOf()
setStackTraceFilters(listOf())
}
}

val implementation by configurations
val testImplementation by configurations
val testRuntimeOnly by configurations
dependencies {
implementation(kotlin("stdlib-jdk8"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.3.1")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.3.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.3.1")
testImplementation("org.junit.jupiter:junit-jupiter-api:$jUnitVersion")
testImplementation("org.junit.jupiter:junit-jupiter-params:$jUnitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jUnitVersion")
}

// build.dependsOn(javadoc) // TODO: No public or protected classes found to document
}
1 change: 1 addition & 0 deletions test-project-kotlin/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jUnitVersion = 5.3.1
30 changes: 9 additions & 21 deletions test-project-kotlin/greeter.api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
import org.javamodularity.moduleplugin.extensions.CompileModuleOptions
import org.javamodularity.moduleplugin.tasks.TestModuleOptions
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

//region NO-OP (DSL testing)
tasks {
compileJava {
extensions.configure(CompileModuleOptions::class) {
addModules = listOf()
compileModuleInfoSeparately = false
}
tasks.compileJava {
extensions.configure<CompileModuleOptions> {
addModules = listOf()
compileModuleInfoSeparately = false
}
}

test {
extensions.configure(TestModuleOptions::class) {
addModules = listOf()
runOnClasspath = false
}
tasks.test {
extensions.configure<TestModuleOptions> {
addModules = listOf()
runOnClasspath = false
}
}

modularity {
}
//endregion

val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
41 changes: 16 additions & 25 deletions test-project-kotlin/greeter.javaexec/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
import java.io.FilenameFilter
import org.javamodularity.moduleplugin.tasks.ModularJavaExec
import org.javamodularity.moduleplugin.tasks.ModuleOptions
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val moduleName: String by project

dependencies {
implementation(project(":greeter.api"))
runtimeOnly(project(":greeter.provider"))
}

val moduleName: String by project

for(file in File("${project.projectDir}/src/main/kotlin/demo")
.listFiles(FilenameFilter { _, name -> name.matches(Regex("Demo.*\\.kt"))})) {
val demoClassName = file.name.substring(0, file.name.length - ".kt".length)
tasks.create<ModularJavaExec>("run$demoClassName") {
group = "Demo"
description = "Run the $demoClassName program"
main = "$moduleName/demo.${demoClassName}Kt"
jvmArgs = listOf("-Xmx128m")
}
}

val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
patchModules.config = listOf(
"java.annotation=jsr305-3.0.2.jar"
)

patchModules.config = listOf("java.annotation=jsr305-3.0.2.jar")
File("${project.projectDir}/src/main/kotlin/demo")
.listFiles({ _, name -> Regex("Demo.*\\.kt") matches name })
.forEach { file ->
val demoClassName = file.name.removeSuffix(".kt")
tasks.create<ModularJavaExec>("run$demoClassName") {
group = "Demo"
description = "Run the $demoClassName program"
main = "$moduleName/demo.${demoClassName}Kt"
jvmArgs = listOf("-Xmx128m")
}
}
15 changes: 3 additions & 12 deletions test-project-kotlin/greeter.provider.test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

dependencies {
implementation(project(":greeter.api"))
runtimeOnly(project(":greeter.provider"))
}

val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}

patchModules.config = listOf("java.annotation=jsr305-3.0.2.jar")
patchModules.config = listOf(
"java.annotation=jsr305-3.0.2.jar"
)
23 changes: 13 additions & 10 deletions test-project-kotlin/greeter.provider/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.javamodularity.moduleplugin.tasks.ModuleOptions

dependencies {
implementation(project(":greeter.api"))
compile("javax.annotation:javax.annotation-api:1.3.2")
compile("com.google.code.findbugs:jsr305:3.0.2")

testImplementation("org.hamcrest:hamcrest:2.1+")
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}

patchModules.config = listOf("java.annotation=jsr305-3.0.2.jar")
patchModules.config = listOf(
"java.annotation=jsr305-3.0.2.jar"
)

tasks.javadoc {
extensions.configure<ModuleOptions> {
addModules = listOf("java.sql")
}
}
28 changes: 12 additions & 16 deletions test-project-kotlin/greeter.runner/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
import org.gradle.api.tasks.JavaExec
import org.javamodularity.moduleplugin.tasks.ModuleOptions
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
application
}

//region https://docs.gradle.org/current/userguide/kotlin_dsl.html#using_kotlin_delegated_properties
val moduleName: String by project
val run by tasks.existing(JavaExec::class) // https://youtrack.jetbrains.com/issue/KT-28013
//endregion

dependencies {
implementation(project(":greeter.api"))
runtimeOnly(project(":greeter.provider"))
}

val moduleName: String by project
application {
mainClassName = "$moduleName/examples.RunnerKt"
applicationDefaultJvmArgs = listOf("-XX:+PrintGCDetails")
}

val run by tasks.getting(JavaExec::class) {
extensions.configure(typeOf<ModuleOptions>()) {
patchModules.config = listOf(
"java.annotation=jsr305-3.0.2.jar"
)

(run) {
extensions.configure<ModuleOptions> {
addModules = listOf("java.sql")
}
jvmArgs = listOf("-XX:+PrintGCDetails")
}

val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
jvmArgs = listOf("-XX:+PrintGCDetails")
}

patchModules.config = listOf("java.annotation=jsr305-3.0.2.jar")
Loading

0 comments on commit 95e7a9c

Please sign in to comment.