我正在将maven build迁移到gradle,我正在努力在根项目中定义基本的插件配置。并在子模块中提供特定的配置属性。
以下是一个例子:
root:build.gradle
configure(filterSubprojects(['component'])) {
apply plugin: "org.flywaydb.flyway"
flyway {
url = "jdbc:oracle:thin:@${db.host}:${db.port}:${db.name}"
user = db.owner.name
password = db.owner.password
}
}
specific-subproject-component:build.gradle
ext {
db = [
host : <host>,
port : <port>,
name : <name>,
user : [name: <user-name>, password: <user-password>]
]
}
我收到了这个错误:
Cannot get property 'db' on extra properties extension as it does not exist
可能是非常基本的问题,但我无法弄清楚如何做到这一点。
答案 0 :(得分:6)
这里的问题是,在评估root build.gradle文件时,尚未评估特定组件build.gradle文件,因此当configure块运行时db确实不存在。要解决此问题,您应该能够在root build.gradle文件中声明private boolean spokenTextContainsAnyOfTheCommands(List<String> commands) {
for (int i = 0; i < commands.size(); i++) {
if (spokenText.contains(commands.get(i))) {
currentCommand = commands.get(i);
return true;
}
}
return false;
}
private void handleCommand() {
if (youSaidHello) {
if (spokenTextContainsAnyOfTheCommands(callCommands)) {
int idx = spokenText.indexOf(currentCommand);
String whoToCall = spokenText.substring(idx + currentCommand.length()).trim();
callThisDude(whoToCall);
}
if (spokenTextContainsAnyOfTheCommands(openCommands)) {
int idx = spokenText.indexOf(currentCommand);
String whatToOpen = spokenText.substring(idx + currentCommand.length()).trim();
Intent appIntent = getAppIntent(whatToOpen);
if (appIntent == null) {
theTextView.setText(R.string.text_view_after_negative);
}
else {
theTextView.setText(R.string.text_view_after_afirmative);
startActivity(appIntent);
}
}
}
else {
theTextView.setText(R.string.text_view_after_negative);
}
}
private Intent getAppIntent(String appName) {
String appPackage = null;
PackageManager pm;
pm = getPackageManager();
List<ApplicationInfo> appsInfo = pm.getInstalledApplications(0);
for (int i = 0; i < appsInfo.size(); i++) {
if (appsInfo.get(i).name.toLowerCase().equals(appName.toLowerCase())) {
appPackage = appsInfo.get(i).packageName;
}
}
if (appPackage == null) {
theTextView.setText(R.string.text_view_after_negative);
}
else {
theTextView.setText(R.string.text_view_after_afirmative);
}
return pm.getLaunchIntentForPackage(appPackage);
}
。