Eclipse使用的是 Oxygen.1a Release (4.7.1a)
Working Directory: E:\testScript
Gradle User Home: E:\gradle_cache
Gradle Distribution: Local installation at C:\gradle-4.4
Gradle Version: 4.4
Java Home: C:\Java\jdk1.8.0_152
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: makeJavaDir
:makeJavaDir
success
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
以下是build.gradle中的代码:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'junit:junit:4.12'
}
def createDir={
path->
File dir=new File(path);
if(!dir.exists()){
dir.mkdirs();
}
}
task makeJavaDir(){
def paths=['src/main/resources','src/test/resources'];
doFirst{
paths.forEach(createDir);
System.out.println("success");
System.out.println("name:"+project.name);
}
}
执行结果:
Working Directory: E:\testScript
Gradle User Home: E:\gradle_cache
Gradle Distribution: Local installation at C:\gradle-4.4
Gradle Version: 4.4
Java Home: C:\Java\jdk1.8.0_152
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: makeJavaDir
:makeJavaDir
success
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
刷新一下
多谢回复,已经贴出了代码
最好贴出代码,而不只是执行结果