I have integration tests setup in my build.gradle file as such:
task integrationSetup(dependsOn: jar, type: Exec) {
workingDir "$projectDir/resources/integration"
commandLine 'sh', './start_service.sh'
}
task testIntegration(dependsOn: integrationSetup, type: Test) {
testClassesDirs = sourceSets.testIntegration.output.classesDirs
classpath = sourceSets.testIntegration.runtimeClasspath
ignoreFailures = true
}
task integrationTearDown(dependsOn: testIntegration, type: Exec) {
workingDir "$projectDir/resources/integration"
commandLine 'sh', './stop_service.sh'
}
testIntegration.mustRunAfter integrationSetup
testIntegration.finalizedBy integrationTearDown
integrationTearDown.mustRunAfter testIntegration
However since upgrading the Gradle Wrapper to version 4+ the tasks no longer execute correctly. The final tear down never runs and the service continues. What has changed between version 3 and 4 to change this behaviour. Pretty upsetting Gradle did this without warning or deprecation notices.
One dumb option is to downgrade the Gradle wrapper version (can confirm this setup still works on 3.1). But that shouldn't be necessary IMO.
UPDATE: Made some changes per user #Opal. However still have issue where if any errors occur during integration tests the final tear down does not run.
> Task :compileTestIntegrationJava
Putting task artifact state for task ':compileTestIntegrationJava' into context took 0.0 secs.
file or directory '/home/project/cleaner/src/testIntegration/java', not found
file or directory '/home/project/cleaner/src/testIntegration/java', not found
Executing task ':compileTestIntegrationJava' (up-to-date check took 0.072 secs) due to:
Output property 'destinationDir' file /home/project/cleaner/build/classes/java/testIntegration has changed.
Output property 'destinationDir' file /home/project/cleaner/build/classes/java/testIntegration/com has been removed.
Output property 'destinationDir' file /home/project/cleaner/build/classes/java/testIntegration/com/project has been removed.
All input files are considered out-of-date for incremental task ':compileTestIntegrationJava'.
file or directory '/home/project/cleaner/src/testIntegration/java', not found
Compiling with JDK Java compiler API.
/home/project/cleaner/src/integration/java/com/project/cleaner/CleansRequestsTests.java:415: error: reached end of file while parsing
}
^
1 error
:compileTestIntegrationJava (Thread[Daemon worker Thread 8,5,main]) completed. Took 0.162 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestIntegrationJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
BUILD FAILED in 8s
8 actionable tasks: 8 executed
Stopped 0 worker daemon(s).
In discussion it turned out that OP wants to stop the service started before running test no matter what e.g. compilation errors. It can be done with the following script:
ext.integrationTearDown = {
workingDir "$projectDir/resources/integration"
commandLine 'sh', './stop_service.sh'
}
task(type: Exec, 'stop_service', integrationTearDown)
gradle.buildFinished {
exec integrationTearDown
}
testIntegration.dependsOn integrationSetup
testIntegration.finalizedBy stop_service
With this piece of code the service will be stopped after every build - event if it succeeds. To avoid this behaviour BuildResult which is passed to buildFinished may be used to determine the required behaviour.
Related
I am trying to understand gradle.
I followed the gradle tutorial here: https://docs.gradle.org/current/samples/sample_building_java_applications.html#what_youll_build
In short:
I created a folder: mkdir demo
cd demo
gradle init (so far so good)
Now, I tried to run my application like this: gradlew run.
The first run of the application was successful. However, the subsequent runs kept failing and I got a very non descript error.
> Task :app:run FAILED
Error: Could not find or load main class demo.App
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:run'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_211\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s
2 actionable tasks: 1 executed, 1 up-to-date
Then, I deleted the files inside "Z:\Projects\demo\ .gradle\6.7.1\executionHistory" and I was able to run the application again.
This was happening again and again. Please see attached screenshot:
What am I doing wrong -- how do I fix this so that all calls to 'gradlew run' give me a successful build?
Edit:
I tried it on C: and was able to do 'gradlew run' consistently and get
the 'Hello World' output without any issues. My Z drive is actually an
encrypted VeraCrypt file which has been loaded with letter 'Z'. Not
sure if that is causing problems.
Thanks!
Hello I was facing the issue too, spend a lot of time and now I am sure, that the issue is the file system. I believe that your encrypted partition is using exFAT. Gradle is not able to process this file system properly.
I'm using Gradle build tool and I can't get the source code and docs for spark-core.
I've already searched and applied:
idea {
project {
jdkName = '1.8'
languageLevel = '1.8'
}
module {
downloadJavadoc = true
downloadSources = true
}
}
But it still doesn't work for me. I suppose I'm missing something like rebuild the whole project or download just these pieces.
I applied ./gradlew cleanIdea idea as well.
When I try to click with pressed command on SparkConf.class I press Download Sources I get Sources not found for: org.apache.spark:spark-core_2.12:2.4.5
And the result from the run tab:
21:11:29: Executing task 'DownloadSources'...
:DownloadSources FAILED
BUILD FAILED
Total time: 0.124 secs
FAILURE: Build failed with an exception.
* Where:
Initialization script '/private/var/folders/06/97bzw1l51r59l65thfzs7hd80000gn/T/ijmiscinit1.gradle' line: 14
* What went wrong:
Execution failed for task ':DownloadSources'.
> Could not resolve all dependencies for configuration ':downloadSourcesFrom_MavenRepo_91653a2f-0439-4794-b77a-3812f9926728'.
> java.lang.NullPointerException (no error message)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
21:11:29: Task execution finished 'DownloadSources'.
Here is 2 pretty long task outputs:
DownloadSources --info: https://pastebin.com/D07JmGXT
DownloadSources --stacktrace: https://pastebin.com/6ceKhwrk
Idea.log https://pastebin.com/EQcDxPwb
Latest public Intellij build: 2020.1.1 installed via Toolbox
Latest MacOS: 10.15.4
Java 1.8 jdk-8u251-macosx-x64.dmg, downloaded from oracle.com
Could you please help me to realize what should I do to fix it?
The problem belongs to Scala plugin.
If you face this issue, it doesn't matter on build tool you are using Maven or Gradle probably installation of the Scala plugin solves your problem.
My Intellij report: https://intellij-support.jetbrains.com/hc/en-us/requests/2686145
Well-known bug: https://youtrack.jetbrains.com/issue/IDEA-127193
I have a project which is currently built using Gradle version 1.7 and I'm trying to move to version 4.1 as builds are much faster and dependencies can be downloaded in parallel. However I'm seeing some weird behaviour that I don't quite understand. I have a build.gradle file for a couple of sub projects that overrides the main classes task of the java plugin. In it it runs an ant task that generates classes in the build directory.
task classes(overwrite: true) {
inputs.dir project.ext.inputsPath
outputs.dir "${project.buildDir}/classes/main"
doLast {
ant.taskdef(name: 'xmlbean', classname: 'org.apache.xmlbeans.impl.tool.XMLBean', classpath: configurations.compile.asPath)
ant.xmlbean(srcgendir: "${project.buildDir}/generated-sources/xmlbeans",
classgendir: "${project.buildDir}/classes/main",
javasource: '1.5',
failonerror: true,
includeAntRuntime: false,
classpath: project.configurations.compile.asPath) {
fileset(dir: schemaPath, includes: project.ext.has('inclusionPattern') ? project.ext.inclusionPattern : '*.xsd')
}
}
}
This all works as expected and I get classes generated in { project_dir }/build/classes/main
This is the output i get from the console
> Task :my-task:classes
Putting task artifact state for task ':my-task:classes' into context took 0.0 secs.
Executing task ':my-task:classes' (up-to-date check took 0.002 secs) due to:
[ant:xmlbean] Time to build schema type system: 0.616 seconds
[ant:xmlbean] Time to generate code: 1.512 seconds
[ant:xmlbean] Compiling 226 source files to E:\Development\my-task\build\classes\main
[ant:xmlbean] 4 warnings
> Task :my-task:classes
[ant:xmlbean] Time to compile code: 6.263 seconds
:my-task:classes (Thread[Task worker for ':' Thread 3,5,main]) completed. Took 8.899 secs.
:my-task:jar (Thread[Task worker for ':' Thread 3,5,main]) started.
> Task :my-task:jar
Putting task artifact state for task ':my-task:jar' into context took 0.0 secs.
Executing task ':my-task:jar' (up-to-date check took 0.004 secs) due to:
Output property 'archivePath' file E:\Development\my-task\build\libs\my-task.jar has changed.
:my-task:jar (Thread[Task worker for ':' Thread 3,5,main]) completed. Took 0.012 secs.
:my-task:install (Thread[Task worker for ':' Thread 3,5,main]) started.
> Task :my-task:install
The classes task seems to run twice (not sure if this makes any difference) with the task that runs ant running first. As mentioned earlier I do get classes generated by the ant task.
My problem is that the behaviour between Gradle 1.7 -> 4.1 seems to have changed (As you would expect it to) in that for some reason when the jar task runs my classes inside build/classes/main are not archived into the jar, i just get a blank manifest file. How do I get these classes generated using the ant task into the Jar using the default jar task?
Why are you overriding the classes task? The normal approach would be to create an additional task which writes to a new directory and wire it into the DAG
eg:
apply plugin: 'java'
task xmlBeanClasses {
def inclusionPattern = project.ext.has('inclusionPattern') ? project.ext.inclusionPattern : '*.xsd'
inputs.property 'inclusionPattern', inclusionPattern
inputs.dir project.ext.inputsPath
inputs.dir schemaPath
outputs.dir "$buildDir/classes/xmlbeans"
outputs.dir "$buildDir/generated-sources/xmlbeans"
doLast {
// TODO: generate classes in $buildDir/classes/xmlbeans
}
}
// wire the new task into the DAG
classes.dependsOn xmlBeanClasses
// add the generated classes dir to the "main" classesDirs
// (this dir will now be included in the jar etc)
sourceSets.main.output.classesDirs.add files("$buildDir/classes/xmlbeans")
My project has an interesting issue with Gradle. When running "gradle build" from inside Intellij 13 (windows or linux), I get the following error message:
10:05:48 PM: Executing external task 'build'...
:processResources UP-TO-DATE
:compileAspect FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileAspect'.
> Error creating temporary file
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 7.434 secs
Access is denied
10:05:56 PM: External task execution finished 'build'.
From here, I ran a full debug located here: Pastebin
Which shows it failing in the AjcTask.java file at the below line:
1993 tmpFile = File.createTempFile("argfile", "", userDir);
Might be related to GRADLE-1400 which is for and older version but unresolved. On linux, if I cd to the project directory, I can run "gradle build" without trouble after that first time, then I can run it from Intellij as well without an issue.
Maybe the environment vars getting nuke somehow?
It looks like GRADLE-2532.
user.dir property defaults to C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.1.1\jre\jre\bin in your case which causes Access Denied error.
In IDEA 13.1.2 and previous versions enabling Use customizable gradle wrapper option should help. This will set user.dir to the project root directory.
In IDEA 13.1.3 and later versions there are different workarounds available, check this comment.
I'm writing an ant build script to run regression tests for an application. I need to run the test cases sequentially and only if the previous test run was successful. Is there a way I can look a the output of the build to decide if the next target can be called?
[exec] [revBuild] RC = 1
[exec] -------------------------------------------------
[exec] Result: 1
BUILD SUCCESSFUL
Total time: 3 minutes 23 seconds
In the above output, the called application has failed. Is there a way I can search for the application return code in the build output, based on which the next ant target(to run the next test case) can be called?
You probably just want to set the failonerror attribute of the exec task to true. If you do this and the executable's return status code is anything other than 0, then the buildwill fail.
Youi could also store this status code in a property using the resultproperty attribute, and execute some task only if this property is set (or is not set).