所以如果我有一个gradle项目有这样的结构。我有一个名为special task的任务,我想应用于所有子项目(请参见下面的subprojects块)。我已经把打印放在dolast中,因为我希望它在任务的执行阶段发生。
如何使任务在代码编译时运行?例如,无论是一个子项目还是整个项目。
plugins {
// Apply the application plugin to add support for building a CLI application
id 'application'
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
application {
// Define the main class for the application
mainClassName = 'SubProject'
}
dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:28.0-jre'
}
subprojects {
//Declarations below apply to all subprojects.
//Apply Java to all subprojects
apply plugin: 'java'
//Add jcenter as the default repository for all subprojects.
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
//jcenter()
}
dependencies {
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
task outputSpecial {
//Have this task run during the execution phase of the task.
doLast {
println "Special Task!"
}
}
}
谢谢你的帮助。
暂无答案!
目前还没有任何答案,快来回答吧!