问答详情
源自:4-2 自定义任务

eclipse执行Task提示成功但是并没有生成对应目录,请问是什么原因,谢谢?

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



提问者:困惑的扎扎 2017-12-20 10:14

个回答

  • 慕码人5688569
    2018-03-24 09:50:07

    刷新一下

  • 困惑的扎扎
    2017-12-20 12:18:45

    多谢回复,已经贴出了代码

  • 贰拾叁筆劃
    2017-12-20 11:47:33

    最好贴出代码,而不只是执行结果