Skip to content

Commit

Permalink
[#71] add property to better configure if source artefacts are created (
Browse files Browse the repository at this point in the history
#72)

Signed-off-by: Clemens Grabmann <[email protected]>
  • Loading branch information
cgrabmann authored Aug 3, 2022
1 parent 7a4018f commit 53771d4
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ javaConfigure {
vendorName.set("Cloudflight")
applicationBuild.set(false)
encoding.set("UTF-8")
createSourceArtifacts.set(false)
}
````

Expand Down Expand Up @@ -102,6 +103,11 @@ Gradle-Version: 7.3.3
* `Implementation-Title` is your `project.name`
* The `Implementation-Vendor` can be set by configuring the `vendorName` in the `JavaConfigurePluginExtension` (see above)

#### Artifacts

Per default the source and javadoc jars will be generated for all builds that have the property `applicationBuild` set to `false`.
If you want to change that behavior you can manually set the `createSourceArtifacts` depending on the desired outcome.

### Kotlin Plugin

If the plugin detects either the folder `src/main/kotlin` or `src/test/kotlin` in a module, it automatically
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class JavaConfigurePlugin : Plugin<Project> {
encoding.convention(JAVA_ENCODING)
vendorName.convention(VENDOR_NAME)
applicationBuild.convention(false)
createSourceArtifacts.convention(applicationBuild.map { !it })
applicationFramework.convention(ApplicationFramework.SpringBoot)
}

Expand All @@ -55,9 +56,12 @@ class JavaConfigurePlugin : Plugin<Project> {

project.afterEvaluate {

if (!javaConfigureExtension.applicationBuild.get()) {
if (javaConfigureExtension.createSourceArtifacts.get()) {
javaPluginExtension.withSourcesJar()
} else {
javaPluginExtension.withJavadocJar()
}

if (javaConfigureExtension.applicationBuild.get()){
when (javaConfigureExtension.applicationFramework.get()) {
ApplicationFramework.SpringBoot -> {
if (BuildUtils.isIntegrationBuild()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion
abstract class JavaConfigurePluginExtension {

abstract val applicationBuild: Property<Boolean>
abstract val createSourceArtifacts: Property<Boolean>
abstract val applicationFramework: Property<ApplicationFramework>
abstract val languageVersion: Property<JavaLanguageVersion>
abstract val encoding: Property<String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class KotlinConfigurePlugin : Plugin<Project> {

val kotlinConfigureExtension = extensions.getByType(KotlinConfigurePluginExtension::class)

val kotlin = extensions.getByType(KotlinProjectExtension::class.java)
val kotlin = extensions.getByType(KotlinProjectExtension::class)
kotlin.sourceSets.maybeCreate("main").dependencies {
// see https://kotlinlang.org/docs/gradle.html#dependency-on-the-standard-library
// as we allow clients to override the Kotlin Version, (i.e. to 1.5.20), we also want to ensure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import com.github.gradle.node.npm.task.NpmTask
import io.cloudflight.gradle.autoconfigure.AutoConfigureGradlePlugin
import io.cloudflight.gradle.autoconfigure.extentions.gradle.api.plugins.apply
import io.cloudflight.gradle.autoconfigure.extentions.gradle.api.plugins.create
import io.cloudflight.gradle.autoconfigure.extentions.gradle.api.plugins.getByType
import io.cloudflight.gradle.autoconfigure.java.JavaConfigurePlugin
import io.cloudflight.gradle.autoconfigure.java.JavaConfigurePluginExtension
import io.cloudflight.gradle.autoconfigure.util.BuildUtils.isIntegrationBuild
import io.cloudflight.gradle.autoconfigure.util.EnvironmentUtils.isVerifyBuild
import org.gradle.api.Plugin
Expand Down Expand Up @@ -46,6 +48,10 @@ class NodeConfigurePlugin : Plugin<Project> {
)
}

project.extensions.getByType(JavaConfigurePluginExtension::class).apply {
createSourceArtifacts.set(false)
}


val dummy = NodeExtension(project.rootProject)
// Ensure node is only downloaded once for all subprojects
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
plugins {
id "io.cloudflight.autoconfigure.java-configure"
}

repositories {
mavenCentral()
}

description "Cloudflight Gradle Test"
group "io.cloudflight.gradle"
version "1.0.0"

javaConfigure {
applicationBuild = false
languageVersion = JavaLanguageVersion.of(8)
encoding = "UTF-8"
vendorName = "Cloudflight XYZ"
createSourceArtifacts = false
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
}

tasks.getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME).doLast {
def javaPluginExtension = project.extensions.getByType(JavaPluginExtension)
logger.quiet("javaPluginExtension.modularity.inferModulePath: {}", javaPluginExtension.modularity.inferModulePath.get())
logger.quiet("javaPluginExtension.sourceCompatibility: {}", javaPluginExtension.sourceCompatibility)
logger.quiet("javaPluginExtension.targetCompatibility: {}", javaPluginExtension.targetCompatibility)
logger.quiet("compileJava.options.encoding: {}", options.encoding)
}

tasks.getByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME).doLast {
logger.quiet("compileTestJava.options.encoding: {}", options.encoding)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'single-java-module-library-no-sources'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.cloudflight.gradle;

public class Foo {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import org.junit.jupiter.api.Test;

public class FooTest {
@Test
public void test() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ class JavaConfigurePluginTest {
assertThat(outJarLibPath).exists().isRegularFile

val outJarSourcesPath = outJarDirPath.resolve("$fixtureName$versionSuffix-sources.jar")
val outJarJavadocPath = outJarDirPath.resolve("$fixtureName$versionSuffix-javadoc.jar")
if (options.createsSourceJar) {
assertThat(outJarSourcesPath).exists().isRegularFile
assertThat(outJarJavadocPath).exists().isRegularFile
} else {
assertThat(outJarSourcesPath).doesNotExist()
}
Expand Down Expand Up @@ -106,6 +108,16 @@ class JavaConfigurePluginTest {
inferModulePath = true
)
),
arguments(
TestOptions(
fixtureName = "single-java-module-library-no-sources",
languageVersion = 8,
encoding = "UTF-8",
createsSourceJar = false,
implementationVendor = "Cloudflight XYZ",
inferModulePath = true
)
),
arguments(
TestOptions(
fixtureName = "single-java-module-constraints",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class NodeConfigurePluginTest {
assertThat(map).containsAnyElementsOf(options.tasksThatShouldHaveRun)
}

val outJarDirPath = fixtureDir.resolve("build/libs")
val outJarSourcesPath = outJarDirPath.resolve("$fixtureName-1.0.0-sources.jar")
assertThat(outJarSourcesPath).doesNotExist()

if (options.assertUpToDateRerun) {
val result2 = run(LifecycleBasePlugin.BUILD_TASK_NAME, forceRerunTasks = false)
result2.tasks.forEach {
Expand Down

0 comments on commit 53771d4

Please sign in to comment.