我想读取gradle.properties文件并在build.gradle中使用它。我已经在属性文件中定义了一些参数值,现在想要将这些值传递给参数。这样它就会将此参数值传递给我的主方法。但是我遇到了以下错误:
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')]
}
这是我的build.gradle文件。 gradle.properties文件是:
url =jdbc:mysql://127.0.0.1:3306/name
username =root
password =name
folderPath =C:/Users/name/Desktop/DataBase/
错误信息如下:
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'