Gradle不调用其他模块的默认任务

huangapple go评论74阅读模式
英文:

Gradle does not calling default tasks of other module

问题

我正在按照以下的项目结构进行工作:

    root/
        project-1/
             build.gradle
        project-2/
             build.gradle
    build.gradle
    settings.gradle

root/settings.gradle 的内容如下:

    include 'project-1'
    include 'project-2'

project-1/build.gradle 的内容如下:

    ....

    defaultTasks 'task1', 'task2', 'task3'
这里的 task3 会将 project-1 的构建文件复制到 project-2 的某个目录中。project-2 在构建时需要这些文件。

project-2/build.gradle 的内容如下:

    ...

    dependencies {
      compile 'xyx.jar'
      compile 'pqr.jar'
      implementation project(":project-1:defaultTasks")
    }

当我构建 project-2 时,并不会构建 project-1 的 defaultTasks。
英文:

I am working project structure like below

root/
    project-1/
         build.gradle
    project-2/
         build.gradle
build.gradle
settings.gradle

root/settings.gradle is look like below

include 'project-1'
include 'project-2'

project-1/build.gradle is like below

....

defaultTasks 'task1','task2','task3'

Here task3 does copies build file of project-1 to one of directory of project-2. Project-2 need this files for building.

project-2/build.gradle is like below

...

dependencies {
  compile 'xyx.jar'
  compile 'pqr.jar'
  implementation project(":project-1:defaultTasks")

}

When I build project-2, it does not build defaultTasks of project-1.

答案1

得分: 0

defaultTasks仅是在不附加任何任务参数调用gradle时执行的任务。

如果您希望在将项目用作另一个项目的依赖时执行其他任务,您需要将这些任务注册为相应项目构建任务(例如jarassemble)的任务依赖项。

英文:

The defaultTasks are just the tasks that are executed when gradle is called without any tasks as arguments.

If you want additional tasks to be executed when a project is used as an dependency of another project, you need to register those tasks as task dependencies of the tasks that build the respective project (e.g. jar or assemble)

答案2

得分: 0

我可以使用Gradle的compileJava任务来解决这个问题。

project-1/build.gradle看起来像这样:

....

compileJava.dependsOn task3
task3.dependsOn task2
task2.dependsOn task1

现在project-2/build.gradle将会是这样:

...

dependencies {
  compile 'xyx.jar'
  compile 'pqr.jar'
  compile 'project-1'
}

project-2会自动构建project-1,并执行所有所需的任务。

英文:

I can able to solve using gradle's compileJava task

project-1/build.gradle is look like

....

compileJava.dependsOn task3
task3.dependsOn task2
task2.dependsOn task1

and now project-2/build.gradle will look like

...

dependencies {
  compile 'xyx.jar'
  compile 'pqr.jar'
  compile 'project-1'
}

project-2 automatically build project-1 with all desired tasks

huangapple
  • 本文由 发表于 2020年8月29日 20:00:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63646720.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定