对于我的Java项目,我有一个build.gradle文件:
application {
mainClass = 'com.example.passwordsafe.presentation.gui.MainGui2'
// mainClass = 'com.example.passwordsafe.presentation.terminal.MainTerminal'
}
我的项目有两个用户接口,即终端和GUI。如您所见,目前我通过评论一行来更改界面。我想让主级取决于配置文件。我已经有一个为项目的config.properties文件。我想在那里添加一条线,例如:
# UI: terminal or gui
UI=terminal
我需要修改我的build.gradle文件,以便主级取决于配置文件?我想使用现有的配置文件,但是如果有必要的话,也可以创建一个新的配置文件。
def config = new Properties()
file('config.properties').withReader { config.load(it) }
application {
switch(config.UI) {
case 'terminal':
mainClass = 'com.example.passwordsafe.presentation.terminal.MainTerminal'
break
case 'gui':
mainClass = 'com.example.passwordsafe.presentation.gui.MainGui2'
break
default:
throw new RuntimeException("Unknown UI setting '${config.UI}'")
}
}