I am using the gradle-svntools-plugin to attempt to update my svn source etc. but am getting the following error when executing the task
A problem occurred evaluating root project 'XBRLReports'.
Cannot cast object '12345' with class 'java.lang.String' to class 'java.lang.Long'
Here is the task in question :
task updateSource(type: SvnUpdate){
username = svn_username
password = svn_password
if ( project.hasProperty("rev") ) {
revision = rev
println "Revision --- $rev"
}
doLast{
println "Revision --- " + revision
}
}
The issue arises when I try and pass a command line variable like so
gradlew updateSource -Prev=12345
Manually setting revision to a static value also causes the issue. Printing out the value of revision returns null. I am not sure if this is a bug or if I am not properly using the plugin. The documentation is vague for this task. Here is the link to it --
gradle-svntools-plugin SvnUpdate
I have opened a ticket on github as well.
Thank you
Try this :
if ( project.hasProperty("rev") ) {
revision = rev.toLong()
println "Revision --- $rev"
}
Related
For example, if I wanted a shell script to be able to get the value of rootProject.name, how could I do this? Ideally, I'd like to invoke ./gradlew with some set of arguments and have it print the property value (and nothing else) to stdout.
For clarity, here is my Gradle wrapper version:
$ ./gradlew --version
------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------
Build time: 2019-04-26 08:14:42 UTC
Revision: 261d171646b36a6a28d5a19a69676cd098a4c19d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9-LTS)
OS: Mac OS X 10.14.4 x86_64
This is an existing task to give you an idea of the properties available:
$ ./gradlew properties
> Task :properties
------------------------------------------------------------
Root project
------------------------------------------------------------
allprojects: [root project 'myProject', project ':otherProject', ...]
...
rootDir: /path/to/rootDir
rootProject: root project 'myProject'
...
version: 2.3.0
...
Here is a custom task I've built to print out a project property
class ResolveProperties extends DefaultTask {
#Input
String prop
ResolveProperties() {
// if no --prop=<property> is provided, default to spitting out all properties
prop = "properties"
}
#Option(option = 'prop', description = 'Set the property to be evaluated for the project.')
void setProp(final String prop) {
this.prop = prop
}
#TaskAction
void resolveProp() {
List<String> propPath = this.prop.tokenize('.')
int n = propPath.size()
def currentProp = project
propPath.eachWithIndex { p, i ->
if(currentProp.hasProperty(p)) {
currentProp = currentProp.property(p)
}
else {
throw new GradleException("failed to resolve property: ${this.prop}")
}
}
println "${this.prop} -> ${currentProp}"
}
}
task resolveProperties(type: ResolveProperties)
And this is how I use my custom task with a --prop parameter (indicated by #Option(option = 'prop'. I'm using the -q (quiet) Gradle option to suppress some of the extra output.
$ ./gradlew -q resolveProperties --prop=rootProject.name
rootProject.name -> onestop
resolveProperties took 0 seconds
$ ./gradlew -q resolveProperties --prop=rootProject.version
rootProject.version -> 2.3.0
resolveProperties took 0 seconds
$ ./gradlew -q resolveProperties --prop=rootProject.group
rootProject.group -> org.cedar.onestop
resolveProperties took 0 seconds
Because we are throwing a GradleException when we can't find the property, in Bash you can check the return code of the command to know when to parse out the value. The formatting of a successful output is up to you and you could make it easily parsed.
$ ./gradlew -q resolveProperties --prop=does.not.exist
resolveProperties took 0 seconds
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/elliott/Documents/GitHub/onestop/build.gradle' line: 259
* What went wrong:
Execution failed for task ':resolveProperties'.
> failed to resolve property: does.not.exist
* 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 0s
In case of a failure like the one above, we get a non-zero return code in Bash, and we know we don't need to try and parse out the value:
$ echo $?
1
Unfortunately, I don't know a simple way in Gradle to only give the value you are concerned with to stdout (prevent some parsing), but this gets you most of the way there with some flexibility.
If it is still relevant ...
Possible Solution A: print value of "rootProject.name" on cmd line
Add task in build.gradle:
/**
* Prints value of property "rootProject.name" to stdout.
*
* Usage: ./gradlew -q printRootProjectName
*/
task printRootProjectName {
doLast {
println(project.findProperty('rootProject').name)
}
}
Possible Solution B: print a property value as provided on cmd line
Add task in build.gradle:
/**
* Print value of property provided in "-Pprop" on command line to stdout.
*
* Usage Example: ./gradlew -q printProperty -Pprop=rootProject.name
*/
task printProperty {
doLast {
// get the "property name" in question from commandline:
String prop = project.findProperty('prop')
if (prop == null) {
return // or use println ...
}
// treat as property name:
Object theProperty = project.findProperty(prop)
if (null == theProperty) {
// try to handle provided information as "nested property"
List < String > thePropPath = prop.split('\\.').toList()
theProperty = project.findProperty(thePropPath.head())
// aux. closure to travel "property path"
def pp = {
s,
t - >
if (s != null && s.hasProperty(t).is(true)) {
return s.property(t)
}
return null
}
thePropPath.tail().each {
item - >
theProperty = pp(theProperty, item)
}
}
println(theProperty ? : "") // or print "null" ...
}
}
I have got a little problem with variables / ext properties in gradle.
In my root project i have this:
task foo {
println project.fooContent
}
in my child project fooContent is defined like this:
ext { fooContent='somethingProjectSpecific' }
When executing :childproject:foo it says variable is not set.
Do you know how to circumvent that problem?
This variable is not set since you try to print it at configuration phase. Try with an action (<<) it will be printed on execution phase:
task foo << {
println project.fooContent
}
I'm very new to gradle so I'm trying to make sense of it. I'm trying to print the custom properties using println and it works when I just use the property. But as soon as I put it in a string it fails and I'm not sure what is going on.
gradle.properties looks like this:
version = '2.0'
description = 'Project Description'
project.ext {
winADTSDKManager = 'SDK Manager.exe'
winADTSDKManagerPath = 'C:/Projects/WinSDKEnv/sdk/adt'
}
in build.gradle I try to run the code:
task androidSDKManager << {
description = 'Run Android SDK Manager'
println project.ext.winADTSDKManagerPath
println 'Starting: $project.ext.winADTSDKManagerPath'
}
The output looks like this:
c:\Projects\Prototypes\STouchGradle>gradle androidSDKManager
:androidSDKManager
'C:/Projects/WinSDKEnv/sdk/adt'
Starting: $project.ext.winADTSDKManagerPath
The second println statement is not printing the path like the one above. Any ideas on what is wrong with what im doing?
Update: 7/27/2014
OK I figured it out. I need to use double quotes like this
println "Starting: $project.ext.winADTSDKManagerPath"
I have searched for a while for this problem and am not able to solve it. I pulled a project down from a private git repo. Some people are able to build while others like myself are getting the following error:
Error:Gradle:Execution failed for task ':ProjectName:buildNative'.
> execCommand == null!
If anybody has encountered this and knows how to fix it, please let me know, it does not seem like a problem which is specific to the project I am on.
I think this is the part in the Gradle file where it is failing:
task buildNative(type: Exec) {
if (System.env.ANDROID_NDK_HOME != null) {
def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
commandLine ndkBuild
} else {
doLast {
println '##################'
println 'Skipping NDK build'
println 'Reason: ANDROID_NDK_HOME not set.'
println '##################'
}
}
}
Seems like you don't have an ANDROID_NDK_HOME environment variable set. The code above doesn't treat that case correctly. As such, the problem is specific to your build. One way to fix it is to replace doLast with doFirst and to insert throw new StopExecutionException() after the printlns. Additionally you may have to set commandLine (or executable) to a dummy value.
I am using gradle to download the selenium chrome driver from maven
webtestsCompile 'org.seleniumhq.selenium:selenium-chrome-driver:2.32.0'
I am trying to use this directly and I see that I get this error :
Caused by:
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list
I have looked up a couple of questions from stack-overflow and other places it requires me to set the value of the property webdriver.chrome.driver to the location where I have downloaded with some-thing like this :
System.setProperty("webdriver.chrome.driver", "path to chrome-driver");
I am wondering what is the best way to go about this ?
EDIT 1:
I verified the java.class.path a snippet of this path looks like this :
/home/bhavya/.gradle/caches/artifacts-26/filestore/org.seleniumhq.selenium/selenium-chrome-driver/2.32.0/jar/14a4e8e32a4129c682c67381f5d7bf11f2327e1/selenium-chrome-driver-2.32.0.jar
This looks like the selenium-chrome-driver is present in the java.class.path.
Edit 2 :
I would want the chrome driver to work irrespective of the operating system that I am using, currently I am on a ubuntu box but a lot of this will get tested on a windows box. When I hard coded the value of the webdriver.chrome.driver to the value in EDIT 1, I am facing the following issue :
java.lang.IllegalStateException: The driver is not executable: /home/bhavya/.gradle/caches/artifacts-26/filestore/org.seleniumhq.selenium/selenium-chrome-driver/2.32.0/jar/14a4e8e32a4129c682c67381f5d7bf11f2327e1/selenium-chrome-driver-2.32.0.jar
Edit 3 :
Task within which I am running the test suite --
task webs(type: Test, dependsOn: updateNodeModules) {
testClassesDir = sourceSets.webtests.output.classesDir
classpath = sourceSets.webtests.runtimeClasspath
def javaHomeBin = new File(System.getProperty("java.home"), "bin");
def javaExec = new File(javaHomeBin, "java").getAbsolutePath();
systemProperties['jar.path'] = jar.archivePath
if(project.hasProperty('url')){
println" url passed as variable is $url"
systemProperties["selenium.webdriver.url"] = "$url"
}
systemProperties["selenium.webbrowser.type"] = "firefox"
if(project.hasProperty('browser')){
println "the browser passed is $browser"
systemProperties["selenium.webbrowser.type"] = "$browser"
}
include '**/UserEditControllerWebTest.class'
doFirst {
println " iterator is $it"
def chrome=configurations.testRuntime.find {
it.name.contains("selenium-chrome-driver")
}.path
println " chrome driver path is $chrome"
systemProperties["webdriver.chrome.driver"]= "$chrome"
}
}
Assuming that you need to set this system property for your tests, you can do something like:
test.doFirst {
systemProperty "webdriver.chrome.driver",
classpath.find {
it.name.contains("selenium-chrome-driver")
}.path
}