Gradle子项目任务未被检测到。

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

Gradle SubProject tasks are not getting picked-up

问题

我有一个Java项目的多模块设置,结构如下。

mainApp
|---> core-module
|       |---> src
|       |---> build.gradle
|       |---> gradle.properties
|       
|---> lib-module
|       |---> src
|       |---> build.gradle
|       |---> gradle.properties
|---> lib-another-module
|       |---> src
|       |---> build.gradle
|       |---> gradle.properties
|---> settings.gradle
|---> build.gradle

mainApp/build.gradle 中,我提到了:

subprojects {
    test.dependsOn "CreateMessageKeys"
    //test.dependsOn ":CreateMessageKeys"
    //test.dependsOn ("CreateMessageKeys")
    //test.dependsOn (":CreateMessageKeys") 这些都不起作用....
}

task CreateMessageKeys(type: CreateMessageKeysTask) {
    destDir = "bundle-common/src/";
    outputClass = "common.messages.MessageKeys";
}

而我的 core-module/build.gradle 有一个测试目标:

test {
    useTestNG() { 
        useDefaultListeners = true
        suites 'test/testng.xml' 
    }
}

但是会出现以下错误。我在这里漏掉了什么?

Caused by: groovy.lang.MissingMethodException: No signature of method: java.lang.String.dependsOn() is applicable for argument types: (String) values: [CreateMessageKeys]
Possible solutions: respondsTo(java.lang.String)

编辑

subprojects {
    test.dependsOn(rootProject.tasks['CreateMessageKeys'])
}

task CreateMessageKeys(type: CreateMessageKeysTask) {
    destDir = "bundle-common/src/";
    outputClass = "common.messages.MessageKeys";
}

它生成了以下错误:

* What went wrong:
A problem occurred evaluating root project 'myApp'.
> Task with name 'CreateMessageKeys' not found in root project 'mainApp'.
英文:

I have a multi-module setup for a Java project with following structure.

mainApp
|--> core-module
|       |--> src
|       |--> build.gradle
|       |--> gradle.properties
|       
|--> lib-module
|       |--> src
|       |--> build.gradle
|       |--> gradle.properties
|--> lib-another-module
|       |--> src
|       |--> build.gradle
|       |--> gradle.properties
|--> settings.gradle
|--> build.gradle

in mainApp/build.gradle I've mentioned

subprojects {
    test.dependsOn "CreateMessageKeys"
    //test.dependsOn ":CreateMessageKeys"
    //test.dependsOn ("CreateMessageKeys")
    //test.dependsOn (":CreateMessageKeys") none of this working....

}

task CreateMessageKeys(type: CreateMessageKeysTask) {
    destDir = "bundle-common/src/";
    outputClass = "common.messages.MessageKeys";
}

and my core-module/build.gradle have a test target as

test {
    useTestNG() { 
        useDefaultListeners = true
        suites 'test/testng.xml' 
    }
}

but getting error as below.. What Am I missing here?

Caused by: groovy.lang.MissingMethodException: No signature of method: java.lang.String.dependsOn() is applicable for argument types: (String) values: [CreateMessageKeys]
Possible solutions: respondsTo(java.lang.String)

Edit

subprojects {
    test.dependsOn(rootProject.tasks['CreateMessageKeys'])
}

task CreateMessageKeys(type: CreateMessageKeysTask) {
    destDir = "bundle-common/src/";
    outputClass = "common.messages.MessageKeys";
}

It generates the error:

* What went wrong:
A problem occurred evaluating root project 'myApp'.
> Task with name 'CreateMessageKeys' not found in root project 'mainApp'.

答案1

得分: 1

任务定义看起来不正确,请参阅定义任务

正确的写法如下:

task ('CreateMessageKeys', type: CreateMessageKeysTask) {
    destDir = "bundle-common/src/";
    outputClass = "common.messages.MessageKeys";
}

或者

task (CreateMessageKeys, type: CreateMessageKeysTask) {
    destDir = "bundle-common/src/";
    outputClass = "common.messages.MessageKeys";
}

与本问题无关:

在你的第二个示例中,可能在评估时任务CreateMessageKeys尚不存在。一个可能的解决方法是:

subprojects.each {
    it.afterEvaluate {
         it.test.dependsOn(...)
    }
}

或者简单地将任务定义放在此代码块之前可能会解决这个问题。

英文:

The task definition does not look correct, see defining tasks.

It should look like this:

task ('CreateMessageKeys', type: CreateMessageKeysTask) {
    destDir = "bundle-common/src/";
    outputClass = "common.messages.MessageKeys";
}

or

task (CreateMessageKeys, type: CreateMessageKeysTask) {
    destDir = "bundle-common/src/";
    outputClass = "common.messages.MessageKeys";
}

Irrelevant to this question:

In your second example, perhaps the task CreateMessageKeys does not exist yet when this is evaluated. One possible workaround would be the following:

subprojects.each {
    it.afterEvaluate {
         it.test.dependsOn(...)
    }
}

Or simply putting the task definition above this block could resolve this.

huangapple
  • 本文由 发表于 2020年8月17日 19:42:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/63450111.html
匿名

发表评论

匿名网友

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

确定