I have simple build.gradle (or any build.gradle with task that has println)
println GradleVersion.current().prettyPrint()
task task1{
println 'task1 starting'
}
Now when I run $ gradle build I always see tasks executing or print output
task1 starting
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 1.291 secs
Why there is always output from println inside tasks?
If You have the following piece of code:
task task1 {
println 'task1 starting'
}
You're in configuration phase of a task. This phase is run during script evaluation. If You'd like to print something while task is executed You need to add an action for task.
It looks like:
task task1 << {
println 'task1 action'
}
This piece of code will be evaluated while the task is being run. << is exactly the same as invoking doLast method on Task's object. You can add many actions.
EDIT
I also highly encourage you to read this blog post.
from Chapter 55. The Build Lifecycle http://www.gradle.org/docs/current/userguide/build_lifecycle.html
// in `settings.gradle`
// println 'This is executed during the initialization phase.'
println 'This is executed during the configuration phase.'
task configure {
println 'This is also executed during the configuration phase.'
}
task execute << {
println 'This is executed during the execution phase.'
}
run with gradle help
output:
This is executed during the initialization phase.
This is executed during the configuration phase.
This is also executed during the configuration phase.
:help
Welcome to Gradle 1.10.
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
BUILD SUCCESSFUL
Total time: 1.882 secs
Related
Tried the following:
buildTypes {
release {
//Full debug for uploading production and beta builds.
ndk.debugSymbolLevel "FULL"
println 'Full debug for uploading production and beta builds.'
}
debug {
//Small debug info for uploading internal testing builds.
ndk.debugSymbolLevel "SYMBOL_TABLE"
println 'Small debug info for uploading internal testing builds.'
}
}
But the both messages are printed:
Full debug for uploading production and beta builds.
Small debug info for uploading internal testing builds.
> Task :preBuild UP-TO-DATE
> Task :preDebugBuild UP-TO-DATE
> Task :mergeDebugJniLibFolders
...
Does this mean that both release and debug are built?
I have let gradle generate a gradle app for me (gradle init --type=kotlin-application).
It users kotlin-test (org.jetbrains.kotlin:kotlin-test) as test framework.
However, when I invoke "./gradlew build" and a test fails, I get output where the actual failed test assertion is missing, for example
de.eekboom.eeksv.SimplestTest > testStreaming FAILED
java.lang.AssertionError at SimplestTest.kt:48
5 tests completed, 1 failed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///D:/dev/eeksv/build> /reports/tests/test/index.html
I can of course, open the linked index.html for test results, but that is a bit annoying.
Only when I run that specific test (from within IDEA) I get more helpful output like
expected:<3> but was:<2>
java.lang.AssertionError: expected:<3> but was:<2>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:834)
...
at de.eekboom.eeksv.SimplestTest.testStreaming(SimplestTest.kt:48)
When I use Java and the gradle groovy DSL, I can fix this by configuring the test task:
testLogging {
events TestLogEvent.FAILED // Show specific test failures in output
exceptionFormat = TestExceptionFormat.FULL // Output full failure details
}
How can I do the same for kotlin?
apply plugin: 'base'
gradle tasks
Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.
Configure test task
test {
dependsOn bar
}
Error
Could not find method test() for arguments
[build_740ewxgjzod99mmq37aj1jekp$_run_closure17#3e64d862]
on root project 'foo' of type org.gradle.api.Project.
In Gradle doc, it said:
Adds the standard lifecycle tasks and configures reasonable defaults
for the archive tasks:
adds build ConfigurationName tasks. Those tasks assemble the artifacts belonging to the specified configuration.
adds upload ConfigurationName tasks. Those tasks assemble and upload the artifacts belonging to the specified configuration.
configures reasonable default values for all archive tasks (e.g. tasks that inherit from AbstractArchiveTask).
As you can see, there is no test task, you can also verify in the source code:
public void apply(Project project) {
project.getPluginManager().apply(LifecycleBasePlugin.class);
BasePluginConvention convention = new BasePluginConvention(project);
project.getConvention().getPlugins().put("base", convention);
configureBuildConfigurationRule(project);
configureUploadRules(project);
configureUploadArchivesTask();
configureArchiveDefaults(project, convention);
configureConfigurations(project);
configureAssemble((ProjectInternal) project);
}
So, the test task you are looking for is in either 'groovy' (groovy plugin includes java plugin) or 'java' plugin Gradle doc:
> gradle build
:compileJava
:processResources
:classes
:jar
:assemble
:compileTestJava
:processTestResources
:testClasses
:test
:check
:build
BUILD SUCCESSFUL
Total time: 1 secs
Let me know if this makes sense.
I have a Jenkins that run several task, included my tests with phpunit. Everything is working, the test are running but when a test fail the build is set like Succesfull and I don't get my notifications. I wanna that when a test fail, the build fail to notificate github and the developer too.
The notification system works OK when a build fail because I have migrations too that are working ok.
My phpunit.xml file look like this:
<phpunit
backupGlobals="true"
backupStaticAttributes="false"
bootstrap="bootstrap.php"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
processIsolation="false"
stopOnError="true"
stopOnFailure="true"
stopOnIncomplete="true"
stopOnSkipped="true"
stopOnRisky="true"
strict="false"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
verbose="true"
And this is one of the outputs of Jenkins.
There was 1 error:
Undefined index: payroll
/tmp/app/test/unit/payroll/PayrollTest.php:24
FAILURES!
Tests: 311, Assertions: 392, Errors: 1.
BUILD FINISHED
Total time: 2 minutes 17.89 seconds
[INFO] HipChat notification sent to the following rooms: app
Finished: SUCCESS
Hints ? Best regards.
In the "old days", the build tool knew when it had and didn't have to rebuild an application by
looking at the time stamps of the individual source files. Why does Gradle, the most modern tool
for building Android application, use 17 seconds in my case to do god knows what, before deplyoing
and launching an app that is not changed since last build?
The first 8 seconds seems to be spent on building the build script ("Configuring")
The next 9 seconds is spent on running the following task:
:app:preBuild
:app:preDebugBuild
:app:checkDebugManifest
:app:preReleaseBuild
:library:compileLint
:library:copyReleaseLint UP-TO-DATE
:library:mergeReleaseProguardFiles UP-TO-DATE
:library:preBuild
:library:preReleaseBuild
:library:checkReleaseManifest
:library:preDebugBuild
:library:preDebugTestBuild
:library:prepareComAndroidSupportAppcompatV71910Library UP-TO-DATE
:library:prepareComGoogleAndroidGmsPlayServices3265Library UP-TO-DATE
:library:prepareReleaseDependencies
:library:compileReleaseAidl UP-TO-DATE
:library:compileReleaseRenderscript UP-TO-DATE
:library:generateReleaseBuildConfig UP-TO-DATE
:library:generateReleaseAssets UP-TO-DATE
:library:mergeReleaseAssets
:library:processReleaseManifest UP-TO-DATE
:library:crashlyticsCleanupResourcesRelease
:library:crashlyticsUploadStoredDeobsRelease
:library:crashlyticsGenerateResourcesRelease
:library:generateReleaseResValues UP-TO-DATE
:library:generateReleaseResources UP-TO-DATE
:library:mergeReleaseResources
:library:processReleaseResources
:library:generateReleaseSources
:library:compileReleaseJava UP-TO-DATE
:library:processReleaseJavaRes UP-TO-DATE
:library:packageReleaseJar UP-TO-DATE
:library:compileReleaseNdk UP-TO-DATE
:library:packageReleaseJniLibs UP-TO-DATE
:library:packageReleaseLocalJar UP-TO-DATE
:library:packageReleaseRenderscript UP-TO-DATE
:library:packageReleaseResources
:library:bundleRelease
:app:prepareComAndroidSupportAppcompatV71910Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServices5089Library UP-TO-DATE
:app:prepareComMixpanelAndroidMixpanelAndroid431Library UP-TO-DATE
:app:prepareVGSwipelibraryUnspecifiedLibrary
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:processDebugManifest UP-TO-DATE
:app:crashlyticsCleanupResourcesDebug
:app:crashlyticsUploadStoredDeobsDebug
:app:crashlyticsGenerateResourcesDebug
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources
:app:processDebugResources
:app:generateDebugSources
:app:compileDebugJava UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug UP-TO-DATE
:app:crashlyticsStoreDeobsDebug
:app:crashlyticsUploadDeobsDebug
:app:crashlyticsCleanupResourcesAfterUploadDebug
:app:compileDebugNdk UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug
:app:zipalignDebug
:app:assembleDebug
:library:copyDebugLint UP-TO-DATE
:library:mergeDebugProguardFiles UP-TO-DATE
:library:checkDebugManifest
:library:prepareDebugDependencies
:library:compileDebugAidl UP-TO-DATE
:library:compileDebugRenderscript UP-TO-DATE
:library:generateDebugBuildConfig UP-TO-DATE
:library:generateDebugAssets UP-TO-DATE
:library:mergeDebugAssets
:library:processDebugManifest UP-TO-DATE
:library:crashlyticsCleanupResourcesDebug
:library:crashlyticsUploadStoredDeobsDebug
:library:crashlyticsGenerateResourcesDebug
:library:generateDebugResValues UP-TO-DATE
:library:generateDebugResources UP-TO-DATE
:library:mergeDebugResources
:library:processDebugResources
:library:generateDebugSources
:library:compileDebugJava UP-TO-DATE
:library:processDebugJavaRes UP-TO-DATE
:library:packageDebugJar UP-TO-DATE
:library:compileDebugNdk UP-TO-DATE
:library:packageDebugJniLibs UP-TO-DATE
:library:packageDebugLocalJar UP-TO-DATE
:library:packageDebugRenderscript UP-TO-DATE
:library:packageDebugResources
:library:bundleDebug
:library:crashlyticsStoreDeobsDebug
:library:crashlyticsUploadDeobsDebug
:library:crashlyticsCleanupResourcesAfterUploadDebug
:library:assembleDebug
What happened? Why does I as a developer need to spend 17 seconds waiting for the build system to determine that nothing has changed?
Is there hacks to work around this shortcoming, so that when I simply want to relaunch my app from Android Studio I don't need to wait for it to recompile?
I know I can create a Run configuration where I remove the "Make" step,
but then the process of determining whether anything is changed or not,
is left up to me as a developer to decide. I don't think that's an acceptable solution.
Use gradle daemon, configure it using gradle.properties.
The Gradle daemon (sometimes referred as the build daemon) aims to improve the startup and execution time of Gradle
Gradle is java based tool.
Most of the time is spent starting JVM. Your 8 and 9 seconds are due to Java Compiling and JVM starting. Gradle daemon will offset these issues.
TL;DR;
Gradle daemon will make your builds a lot faster.
Add gradle.properties file to same folder as your build.gradle. Add following property this file.
org.gradle.daemon=true
See two runs of gradle
P:\github\WekaExamples>gradle
:help
Welcome to Gradle 2.2.
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
BUILD SUCCESSFUL
Total time: 14.545 secs
P:\github\WekaExamples>gradle
:help
Welcome to Gradle 2.2.
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
BUILD SUCCESSFUL
Total time: 3.578 secs
Second one is a lot faster due to gradle daemon.