I have a gradle script that uses Sonarqube plugin (org.sonarqube). If I let the publish task depends on it, it works fine.
The problem is to run sonarqube only if a condition is true. So I tried (as described in gradle documentation) all of these three statements:
sonarqube.enabled (false)
sonarqube.enabled=false
sonarqube.onlyIf { false }
Each results in an error, here the one I got trying the first statement
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\Eclipse\workspace3.6\at.mic.hermes\build.gradle' line: 208
* What went wrong:
A problem occurred evaluating root project 'at.mic.hermes'.
> Could not find method enabled() for arguments [false] on org.sonarqube.gradle.SonarQubeExtension_Decorated#412196.
To be sure to have not typo in the code I tried all statements with the test task, e.g.
test.enabled(false)
and this results (as expeted) in
:test SKIPPED
Any ideas what I made wrong / what must be changed? Thx in advance!
Frank
I think the problem come from a name conflict. There are 2 objects named 'sonarqube':
The SonarQube task
The SonarQube extension
It seems to not break your build, but here when you write sonarqube.enabled it access to the extension (according to your stacktrace).
The solution is probably to disambiguate using tasks.sonarqube.enabled. See https://docs.gradle.org/current/userguide/more_about_tasks.html#N11143
Related
I'm trying to build a kjar from our existing drools project with lots of individual rules file.
To speed up deployment I would like to generate the model into the kjar as introduced with Drools 7.7.0.Final.
The command I use is: mvn clean install -DgenerateModel=WITHDRL -X
Pretty soon I get an error message:
[ERROR] Failed to execute goal org.kie:kie-maven-plugin:7.7.0.Final:generateModel (default-generateModel) on project foobar: Execution default-generateModel of goal org.kie:kie-maven-plugin:7.7.0.Final:generateModel failed: (line 1,col 33) Parse error. Found ",", expected one of "%=" "&=" "*=" "++" "+=" "--" "-=" "/=" ";" "<<=" "=" ">>=" ">>>=" "^=" "|="
[ERROR] Problem stacktrace :
[ERROR] org.drools.javaparser.GeneratedJavaParser.generateParseException(GeneratedJavaParser.java:11460)
There is no information in which file this error occured. Since our project contains >300 DRL Files it is a bit hard to find the culprit.
Is there any way to get more information out of the Drools Maven Plugin on which file is causing the issue?
That's bug of kie-maven-plugin.
There are the bug's JIRA below.
DROOLS-3505
DROOLS-3523
If dialect is java and your rules have connect expressions with "comma" inside a modify block, The workaround is that
property inside modify block one by one.
the other workaround is changing dialect to mvel.
But, you have to write 'dialect "mvel"' in each rule file.
because dialect species isn't shared in package.
I am facing some issue while building spring-framework source, what is the issue?
FAILURE: Build failed with an exception.
Where:
Build file '/home/steph/workspace_sts/spring-framework/spring-beans/spring-beans.gradle' line: 30
What went wrong:
A problem occurred evaluating project ':spring-beans'.
> No such property: values for class: org.gradle.api.internal.tasks.DefaultTaskDependency
Possible solutions: values
It seems to be saying that the class DefaultTaskDependency does not have a field and getter/setter called getValues()/setValues() but the gradle build file is passing in some data which it is trying to set by calling setValues() and passing whatever data is in the gradle.build file under values. I would double check which version of gradle spring source says it needs to be built with vs. what version you are building it with.
Based on references below:
https://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-dependency-management/
I believe I can specify multiple dependencies under a dependency configuration like below:
However, when I try to run gradle build, I see the following errors.
Is this not the right way to provide multiple dependencies in a gradle file?
D:\TestGradle>gradle build
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\TestGradle\build-ProblemTemplate.gradle' line: 116
* What went wrong:
Could not compile build file 'D:\TestGradle\build-ProblemTemplate.gradle'.
> startup failed:
build file 'D:\TestGradle\build-ProblemTemplate.gradle': 116: expecting ')', found ',' # line 116, column 68.
toolVersions.mockitoVersion}'],
^
1 error
* 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 1s
D:\TestGradle>
Also tried removing the [] in the testCompile configuration as mentioned in answer from Jakub Wójcik below. But still get the same error.
Update
Surprisingly, removing the line break after dependency configuration name worked for me.
It worked fine with or with out [] brackets. Still don't know why this matters, but updating the thread with my findings so far.
You can try specifying the dependencies with the configuration for each one of them. I think this is most common and used way.
dependencies {
compile 'dep1'
compile 'dep2'
}
or if you really want to just pass in a comma-separated args to compile closure.
dependencies {
compile (
'dep1',
'dep2'
)
}
PS. When using $variables you need to use the GString " (double quotes).
PPS. You can pass a vararg or an array to the configuration it doesn't really matter.
For the new lines
Gradle uses groovy for its scripts and this is not a bug its intentional actually, because () or {} may be interpreted as a separate block for the compiler. Refer to Context-sensitive_grammar
Its all to Groovy parser at the end of the day :)
Try removing the [] brackets, when having multiple dependencies for a testCompile clause. Also, note that you have an extra " in the line 118.
I created a gradle ant task based on example from [http://mrhaki.blogspot.in/2009/12/gradle-goodness-using-optional-ant-task.html]
Below is the example code that works for me:
ant.scp(
todir: 'myUserid:myPasswd#servername:/home/myUserid',
trust:"true",
verbose: 'true'
) {
fileset(dir: 'work') {
include(name: '**/**')
}
}
For the todir: instead of myUserid:myPasswd#servername:/home/myUserid I used the following properties defined in gradle.properties file "${remoteUser}:${remoteUserPasswd}#${remoteSSHMachine}:${remoteLocation}"
This gives me an error
* What went wrong:
A problem occurred evaluating script.
> com.jcraft.jsch.JSchException: java.net.UnknownHostException: ${remoteSSHMachine}
remoteSSHMachine = server is already defined in the gradle.properties file so I'm not sure why java.net.UnknownHostException exception should occur.
Amy help in this regard is appreciated.
Hard to say what exactly does not work, but I've prepared a demo that, admittedly, fails but with unknown host exception - properties from gradle.properties file are read correctly. Please compare your code with the demo, maybe it will help you somehow.
EDIT
It turned out that double quotes (") in gradle.properties were messing things up.
I am trying to get my one of my projects (ProjectA) to generate a jar file containing all the test classes so that it can be used in ProjectB.
I did a bit of research and found this as possible solution: Create test jar artifact in gradle. That says that the following code snippet should do the trick.
apply plugin: 'java'
task testJar(type: Jar) {
classifier = 'tests'
from sourceSets.test.classes
}
However, when I add the above to my build.gradle, I get the following error message:
What went wrong:
A problem occurred evaluating root project 'gradle_project'.
Could not find property 'sourceSets' on task ':testJar'.
I have searched on both Google and the Gradle documentation for more information but either it has been removed without documenting it anywhere that I could find or I am using it wrong. I am suspecting the latter, just don't know what I am doing wrong.
I have tried the same code snippet inside mysubprojects{} section but then I got the following error message:
What went wrong:
A problem occurred evaluating root project 'gradle_project'.
Cannot get the value of write-only property 'classes' on source set test.
Solved it with the steps below:
Step 1: Move the code snippet inside the subprojects{} section
Step 2: sourceSets.test.classes has been removed. sourceSets.test.output seems to do the trick. Found this: Creating a Jar of test binaries - Gradle