Skip to content

Commit

Permalink
Java base plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohannes committed Dec 4, 2023
1 parent 4b4e5cf commit 6133378
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gradle/plugins/java-base-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
plugins {
`kotlin-dsl`
}

dependencies {
implementation(platform(project(":plugins-platform")))

implementation(project(":base-plugins"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins {
id("java-base")
}

// Expose the ':app' project runtime classpath in every project
val app = configurations.dependencyScope("app") {
withDependencies {
// Depend on ':app' and with this on all its (transitive) dependencies
add(project.dependencies.create(project(":app")))
// Get our own version information from the platform project
add(project.dependencies.create(project.dependencies.platform("org.example.product:platform")))
}
}
val appRuntimeClasspath = configurations.resolvable("appRuntimeClasspath") {
description = "Runtime classpath of the complete application"
extendsFrom(app.get())
attributes {
// We want the runtime classpath represented by Usage.JAVA_RUNTIME
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
}
}

// Every compile classpath and runtime classpath uses the versions of the
sourceSets.all {
configurations[compileClasspathConfigurationName].shouldResolveConsistentlyWith(appRuntimeClasspath.get())
configurations[runtimeClasspathConfigurationName].shouldResolveConsistentlyWith(appRuntimeClasspath.get())
// Source sets without production code (tests / fixtures) are allowed to have dependencies that are
// not part of the consistent resolution result and might need additional version information
if (this != sourceSets["main"]) {
dependencies.add(implementationConfigurationName, dependencies.platform("org.example.product:platform"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
id("java")
id("jacoco") // Record test coverage data during test execution
id("org.example.base")
id("org.example.consistent-resolution")
}

// Configure Java compilation on java {} extension or directly on 'JavaCompile' tasks
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}

// Configure details for *all* test executions directly on 'Test' task
tasks.withType<Test>().configureEach {
useJUnitPlatform() // Use JUnit 5 as test framework
maxParallelForks = 4

testLogging.showStandardStreams = true

maxHeapSize = "1g"
systemProperty("file.encoding", "UTF-8")
}

// Configure common test runtime dependencies for *all* projects
dependencies {
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.slf4j:slf4j-simple")
}

// Add a 'compileAll' task to run all of Java compilation in one go
tasks.register("compileAll") {
group = LifecycleBasePlugin.BUILD_GROUP
description = "Compile all Java code (use to prime the build cache for CI pipeline)"
dependsOn(tasks.withType<JavaCompile>())
}

0 comments on commit 6133378

Please sign in to comment.