showStandardStreams = true
Great but how do I set it on all sub-projects that have the Java plug-in? Better yet, how do I turn it on for only this project from the command line? That way my team can do it without fiddling with the build code.
To set showStandardStreams to true for all sub-projects that have java plugin applied you need the following piece of code:
subprojects.findAll {
it.plugins*.class*.name.any { it.toLowerCase().contains('java')
}.each { p ->
configure(p) {
test {
testLogging.showStandardStreams = true
}
}
}
It cannot be done from commandline. Also, have a look at a demo here.
Related
I have enabled the javadoc for a project with
java {
withJavadocJar()
}
The problem with this is that the javadoc is built everytime the library is built. In my case, this takes several minutes. Is there a good way to make the javadoc only run on gradle deloy?
The following did the trick:
// Disables a task unless we're publishing something.
def disableUnlessPublishing(toDisable) {
toDisable.enabled = false
gradle.taskGraph.whenReady {
gradle.taskGraph.allTasks
.findAll { it.group == "publishing" }
.any { toDisable.enabled = true }
}
}
disableUnlessPublishing(tasks.javadocJar)
disableUnlessPublishing(tasks.javadoc)
disableUnlessPublishing(tasks.sourcesJar)
We have some of our tests in main (so they can be built into and run from a service). The latest Gradle defaults to not recognizing source in main as test code.
I thought I could use the Nebula Facets plugin but the following doesn't work around the problem, either:
facets {
functionalTest {
parentSourceSet = 'main'
includeInCheckLifecycle = false
}
}
If you really need to live with tests in src/main/java, then you do not need an extra source set.
Instead you need to configure a test task so that it uses the main source set classpath.
Here is an example to configure such a test task, using the Kotlin DSL and task configuration avoidance:
val mainTest = tasks.register<Test>("mainTest") {
useJUnitPlatform()
description = "Run tests from main"
group = "verification"
testClassesDirs = sourceSets["main"].output.classesDirs
classpath = sourceSets["main"].runtimeClasspath
}
tasks.named("check").configure {
dependsOn(mainTest)
}
The following is how to override srcDirs:
facets {
functionalTest {
includeInCheckLifecycle = false
}
}
sourceSets {
functionalTest {
java {
srcDirs = ["${projectDir}/src/main/java"]
}
resources {
srcDirs = ["${projectDir}/src/main/resources"]
}
}
}
I am using Gradle 6.0.1 and JDK12 with preview features.
Having the following configuration to be able to compile, run and test:
tasks.withType(JavaCompile) {
options.compilerArgs += "--enable-preview"
}
tasks.withType(Test) {
jvmArgs += "--enable-preview"
}
tasks.withType(JavaExec) {
jvmArgs += '--enable-preview'
}
That works fine for all except javadoc generation that I defined as follows:
task generateJavadocs(type: Javadoc) {
source = sourceSets.main.allJava
options.jFlags("--enable-preview")
}
When running gradle generateJavadocs I receive compilation errors for the new switch expressions. Has anybody made it work with Javadoc?
I had faced the same problem with preview features of JDK 14 (and Gradle 6.3). This has worked for me:
javadoc.options {
addBooleanOption('-enable-preview', true)
addStringOption('-release', '14')
}
In your case, try:
task generateJavadocs(type: Javadoc) {
options {
addBooleanOption('-enable-preview', true)
addStringOption('-release', '12')
}
}
This answer enhances Manfred's answer and is for anybody who is trying to set the javadoc args using gradle's kotlin api. It took me awhile to figure out that access to addStringOption and addBooleanOption requires a cast.
tasks.withType<Javadoc> {
val javadocOptions = options as CoreJavadocOptions
javadocOptions.addStringOption("source", "14")
javadocOptions.addBooleanOption("-enable-preview", true)
}
My custom task at gradle-4.10.1:
task fabricUploadApkDevelop(group: "fabric", dependsOn: ['assembleDevDebug']) {
doLast {
//fabric gradle task `assembleRelease crashlyticsUploadDistributionDevDevelop` and options:
def task = tasks.getByName("crashlyticsUploadDistributionDevDebug")
task.ext.betaDistributionGroupAliases = "develop"
task.ext.betaDistributionNotifications = true
task.ext.betaDistributionReleaseNotesFilePath = "${project.rootDir}/app/build/outputs/apk/dev/debug/releaseNotes.txt"
task.execute()
}
}
But at gradle-5.1.1:
TaskInternal.execute() is removed, so now I can't run my task.execute(), how to change my custom task? Or how to run task crashlyticsUploadDistributionDevDebug with params via terminal?
I tried to use:
//gradle 5.x
task fabricUploadApkDevelop(group: "fabric") {
ext.betaDistributionGroupAliases = "develop"
ext.betaDistributionNotifications = true
ext.betaDistributionReleaseNotesFilePath = "${project.rootDir}/app/build/outputs/apk/dev/debug/releaseNotes.txt"
doLast {
ext.betaDistributionGroupAliases = "develop"
ext.betaDistributionNotifications = true
ext.betaDistributionReleaseNotesFilePath = "${project.rootDir}/app/build/outputs/apk/dev/debug/releaseNotes.txt"
}
finalizedBy 'crashlyticsUploadDistributionDevDebug'
}
But crashlyticsUploadDistributionDevDebug task doesn't get params...
The sources for the Fabric/Crashlytics Gradle plugin don’t seem to be publicly available (and I have never used it myself), otherwise I would have checked there. But given your working example for Gradle 4 and looking at the issue through my vanilla Gradle glasses, I’d expect that the following should/could work with Gradle 5:
project.afterEvaluate {
crashlyticsUploadDistributionDevDebug.doFirst {
ext.betaDistributionGroupAliases = "develop"
ext.betaDistributionNotifications = true
ext.betaDistributionReleaseNotesFilePath = "${project.rootDir}/app/build/outputs/apk/dev/debug/releaseNotes.txt"
}
}
task fabricUploadApkDevelop(group: "fabric") {
dependsOn 'crashlyticsUploadDistributionDevDebug'
}
I’d even expect there to be a nicer way to do it but since I can’t test this myself, I wanted to play it safe. Let me know if it worked or what didn’t!
I am using Gradle's eclipse plugin. For cross-project reference reasons, I need Eclipse's output directory to not be the default bin, rather ecbuild.
Everytime I run ./gradlew eclipse, it overwrites this output directory setting.
How to make sure it doesn't, or how to set it within gradle build script ?
Add this to the build.gradle script:
eclipse {
classpath { defaultOutputDir = file('ecbuild') }
}
This might require you to upgrade the version of your gradle wrapper.
If so, run :
./gradlew wrapper --gradle-version 3.3
In my case, seting defaultOutputDir was not enough. So I did the following:
eclipse {
classpath {
defaultOutputDir = file("build")
file.whenMerged {
entries.each { entry ->
if (entry.kind == 'src' && entry.hasProperty('output')) {
entry.output = entry.output.replace('bin/', "build/")
}
}
}
}
}