I am trying to read gradle.properties into my build.gradle. I have defined some argument values in the property file and now wanted to pass these values to the argument. So that it will pass this argument value to my main methode. But I am getting the following error:
group 'org.name'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'groovy'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile "joda-time:joda-time:2.2"
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.6'
// https://mvnrepository.com/artifact/org.dbunit/dbunit
compile group: 'org.dbunit', name: 'dbunit', version: '2.4.7'
compile "org.slf4j:slf4j-simple:1.7.9";
}
task runApp(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'ExportDatatoXML'
println url
println username
println password
println folderPath
// arguments to pass to the application
args
[project.property('url'),project.property('username'),
project.property('password'),project.property('folderPath')]
}
This is my build.gradle file
gradle.properties file is:
url =jdbc:mysql://127.0.0.1:3306/name
username =root
password =name
folderPath =C:/Users/name/Desktop/DataBase/
Error is following:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\name\IdeaProjects\HelloWorld\build.gradle' line: 36
* What went wrong:
A problem occurred evaluating root project 'AI'.
> Cannot cast object 'jdbc:mysql://127.0.0.1:3306/name' with class
'java.lang.String' to class 'int'
* 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: 12.448 secs
Cannot cast object 'jdbc:mysql://127.0.0.1:3306/name' with class
'java.lang.String' to class 'int'
13:01:41: External task execution finished 'build'