当前位置: 首页 > 知识库问答 >
问题:

Gradle:忽略任务依赖树?

蒋星雨
2023-03-14
clean.dependsOn clearVersionProperties
processResources.dependsOn ([defaultValues,infoEnv])
compileJsps.dependsOn(classes, tomcatJasper, xmlModify)
war.dependsOn(compileJsps, svnRevision, writeVersionProperties)
...

def writeVersionFile(String whatToWrite) {
    File f = new File(project.webAppDirName+'/WEB-INF/version.properties');
    if (f.exists()) { f.delete(); }

    f = new File(project.webAppDirName+'/WEB-INF/version.properties');
    FileOutputStream os = new FileOutputStream(f);
    os.write(whatToWrite.getBytes());
    os.flush();
    os.close();
}

task clearVersionProperties() {
    println "Clearing version file"
    String whatToWrite = "version=@version@"
    writeVersionFile(whatToWrite)
}

task writeVersionProperties(dependsOn: svnRevision) {
    println "Writing version file"
    String whatToWrite = "version="+project.ext.revision;
    writeVersionFile(whatToWrite)
}
...

根据我的理解,clean现在将调用clearVersionProperties,war将调用WriteVersionProperties。

但当我执行分级清洁时,Reactor计划看起来是这样的:

C:\devtools\....\branches\merge\Application>gradle -bbuild20.gradle clean -Ptomcat=7 -Ptarget=live

To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: http://gradle.org/
docs/2.0/userguide/gradle_daemon.html.
_______________________________________________________________________________

### building LIVE system

_______________________________________________________________________________
Clearing version file
Writing version file
JSP compilation...
TC7 Sources integrated
________________________________________________________
Compiling JSPs against Tomcat 7.0.11
________________________________________________________
:clearVersionProperties UP-TO-DATE
:clean UP-TO-DATE

BUILD SUCCESSFUL

Total time: 16.803 secs

为什么要执行clearVersionProperties和writeVersionProperties任务,因为它们绑定到某些构建阶段?例如,不执行任务infoEnv,而是执行任务writeVersionProperties,该任务只应由war任务执行,这确实是一个问题。

共有1个答案

呼延渝
2023-03-14

在此期间,我发现了这些任务被激发的原因:

我错过了任务语句后面的<<,所以将我的两个tak更改为

task clearVersionProperties() << {
    println "Clearing version file"
    String whatToWrite = "version=@version@"
    writeVersionFile(whatToWrite)
}

task writeVersionProperties(dependsOn: [svnRevision]) << {
    println "Writing version file"
    String whatToWrite = "version="+project.ext.revision;
    writeVersionFile(whatToWrite)
}

writeVersionProperties.mustRunAfter clearVersionProperties

这起作用了....我不确定,如果这是一个bug,特性或副作用。但在我看来,这是一个完全邪恶的陷阱,就像在函数之后忘记()一样。

 类似资料:
  • 我有两个互斥的任务,它们都应该在完成后启动。 我提到它们是互斥的,因为我不想让< code>bootRun依赖于它们中的任何一个。相反,我在寻找一个类似如下的流程: 我尝试了以下方法, 因此,将启动设置()和bootRun(与的类似设置)。这会导致在项目'中找不到路径'bootRun'的 我还尝试将A/B任务声明为:< code > task A(type:org . spring framewo

  • 本文向大家介绍Android Gradle依赖管理、去除重复依赖、忽略的方式,包括了Android Gradle依赖管理、去除重复依赖、忽略的方式的使用技巧和注意事项,需要的朋友参考一下 常用依赖 库工程依赖传递问题 1、依赖常用的基本类型有:provided和compile,provided 只在编译生效不会打包到 apk 或 aar 中;compile 是会打包到 apk或 aar 中的(如果

  • 我正在以下项目结构中使用Gradle Android实验插件: 设置.分级 Build.Gradle

  • 我对Gradle完全陌生。首先,我尝试为简单的控制台Java应用程序创建一个构建脚本,而不使用Java插件。maven repository中的代码中只有两个依赖项。因此,我的构建包含一个任务,它扩展了JavaCompile,我在其中指定了类路径、目标等 我的项目不应用java插件,因此我需要自己创建依赖项配置,如下所示: 然后我可以将依赖项绑定到此配置: 据我所知,在那之后我必须将那些配置与我的

  • 我有一些与jdbc相关的通用代码,我想单独打包到一个可运行的jar中,其中已经包含了所需的jdbc库,因此每个数据库类型都有一个单独的可运行jar。源代码将保持不变,但打包的jdbc jar将不同。 例如jdbc app postgres。jar将只包含postgres jdbc jar,而jdbc应用程序mysql。jar将包含mysql jdbc jar。 是否可以使用gradle对任务或任何

  • 我试图通过这个Gradle插件https://github.com/theboegl/gradle-launch4j使用http://launch4j.sourceforge.net/。 当我执行时,我会得到以下输出。 这是我的年级版本信息。 这是我的构建脚本。