首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gradle任务命令失败,但它手动工作。

Gradle任务命令失败,但它手动工作。
EN

Stack Overflow用户
提问于 2019-01-23 17:58:21
回答 2查看 729关注 0票数 0

我的build.gradle文件中有以下任务:

代码语言:javascript
复制
task init_dev {
    doLast {
        exec {
            workingDir '.'
            commandLine 'mongo', '--port', '27018', '<', 'init/mongodb-init-dev'
        }
    }
}

当我执行它时,我得到以下信息

代码语言:javascript
复制
14:52:49: Executing task 'init_dev --info'...

The client will now receive all logging from the daemon (pid: 3919). The daemon log file: /Users/jscherman/.gradle/daemon/4.8.1/daemon-3919.out.log
Starting 42nd build in daemon [uptime: 49 mins 28.148 secs, performance: 99%, no major garbage collections]
Using 8 worker leases.
Starting Build
Settings evaluated using settings file '/Users/jscherman/IdeaProjects/demo/settings.gradle'.
Projects loaded. Root project using build file '/Users/jscherman/IdeaProjects/demo/build.gradle'.
Included projects: [root project 'demo', project ':mock-metrics-generator', project ':demo-be']

> Configure project :
Evaluating root project 'demo' using build file '/Users/jscherman/IdeaProjects/demo/build.gradle'.
Applying dependency management to configuration 'annotationProcessor' in project 'mock-metrics-generator'
Applying dependency management to configuration 'apiElements' in project 'mock-metrics-generator'
Applying dependency management to configuration 'archives' in project 'mock-metrics-generator'
Applying dependency management to configuration 'bootArchives' in project 'mock-metrics-generator'
Applying dependency management to configuration 'compile' in project 'mock-metrics-generator'
Applying dependency management to configuration 'compileClasspath' in project 'mock-metrics-generator'
Applying dependency management to configuration 'compileOnly' in project 'mock-metrics-generator'
Applying dependency management to configuration 'default' in project 'mock-metrics-generator'
Applying dependency management to configuration 'implementation' in project 'mock-metrics-generator'
Applying dependency management to configuration 'runtime' in project 'mock-metrics-generator'
Applying dependency management to configuration 'runtimeClasspath' in project 'mock-metrics-generator'
Applying dependency management to configuration 'runtimeElements' in project 'mock-metrics-generator'
Applying dependency management to configuration 'runtimeOnly' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testAnnotationProcessor' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testCompile' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testCompileClasspath' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testCompileOnly' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testImplementation' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testRuntime' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testRuntimeClasspath' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testRuntimeOnly' in project 'mock-metrics-generator'
Applying dependency management to configuration 'annotationProcessor' in project 'demo-be'
Applying dependency management to configuration 'apiElements' in project 'demo-be'
Applying dependency management to configuration 'archives' in project 'demo-be'
Applying dependency management to configuration 'bootArchives' in project 'demo-be'
Applying dependency management to configuration 'compile' in project 'demo-be'
Applying dependency management to configuration 'compileClasspath' in project 'demo-be'
Applying dependency management to configuration 'compileOnly' in project 'demo-be'
Applying dependency management to configuration 'default' in project 'demo-be'
Applying dependency management to configuration 'implementation' in project 'demo-be'
Applying dependency management to configuration 'runtime' in project 'demo-be'
Applying dependency management to configuration 'runtimeClasspath' in project 'demo-be'
Applying dependency management to configuration 'runtimeElements' in project 'demo-be'
Applying dependency management to configuration 'runtimeOnly' in project 'demo-be'
Applying dependency management to configuration 'testAnnotationProcessor' in project 'demo-be'
Applying dependency management to configuration 'testCompile' in project 'demo-be'
Applying dependency management to configuration 'testCompileClasspath' in project 'demo-be'
Applying dependency management to configuration 'testCompileOnly' in project 'demo-be'
Applying dependency management to configuration 'testImplementation' in project 'demo-be'
Applying dependency management to configuration 'testRuntime' in project 'demo-be'
Applying dependency management to configuration 'testRuntimeClasspath' in project 'demo-be'
Applying dependency management to configuration 'testRuntimeOnly' in project 'demo-be'

> Configure project :mock-metrics-generator
Evaluating project ':mock-metrics-generator' using build file '/Users/jscherman/IdeaProjects/demo/mock-metrics-generator/build.gradle'.

> Configure project :demo-be
Evaluating project ':demo-be' using build file '/Users/jscherman/IdeaProjects/demo/demo-be/build.gradle'.
All projects evaluated.
Selected primary task 'init_dev' from project :
Tasks to be executed: [task ':init_dev']
:init_dev (Thread[Task worker for ':',5,main]) started.

> Task :init_dev FAILED
Task ':init_dev' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
Starting process 'command 'mongo''. Working directory: /Users/jscherman/IdeaProjects/demo Command: mongo --port 27018 < init/mongodb-init-dev
Successfully started process 'command 'mongo''
MongoDB shell version v4.0.3
connecting to: mongodb://127.0.0.1:27018/%3C
Implicit session: session { "id" : UUID("0b3d098a-00e3-4802-bf9f-af7d1f7a6629") }
MongoDB server version: 4.0.3
2019-01-23T14:52:49.741-0300 E QUERY    [js] SyntaxError: missing ; before statement @init/mongodb-init-dev:1:4
failed to load: init/mongodb-init-dev
:init_dev (Thread[Task worker for ':',5,main]) completed. Took 0.217 secs.

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/jscherman/IdeaProjects/demo/build.gradle' line: 60

* What went wrong:
Execution failed for task ':init_dev'.
> Process 'command 'mongo'' finished with non-zero exit value 253

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
1 actionable task: 1 executed
Process 'command 'mongo'' finished with non-zero exit value 253
Open File
14:52:49: Task execution finished 'init_dev --info'.

mongodb-init-dev

代码语言:javascript
复制
use my_db

db.nodes.drop()

db.nodes.insertMany([
    {
        "_id":"node-1",
        "classifier":{
            "lowerThreshold":3000,
            "upperThreshold":5000,
            "timeUnit":"MILLISECONDS"
        }
    },
    {
        "_id":"node-2",
        "classifier":{
            "lowerThreshold":2,
            "upperThreshold":4,
            "timeUnit":"SECONDS"
        }
    },
    {
        "_id":"node-3",
        "classifier":{
            "lowerThreshold":3000,
            "upperThreshold":5000,
            "timeUnit":"MILLISECONDS"
        }
    },
    {
        "_id":"node-4",
        "classifier":{
            "lowerThreshold":1200,
            "upperThreshold":4000,
            "timeUnit":"MILLISECONDS"
        }
    },
    {
        "_id":"node-5",
        "classifier":{
            "lowerThreshold":2000,
            "upperThreshold":5000,
            "timeUnit":"MILLISECONDS"
        }
    }])

现在,当我手动运行该命令时,它可以工作。

代码语言:javascript
复制
madmin’s-MacBook-Pro:demo jscherman$ pwd
/Users/jscherman/IdeaProjects/demo
madmin’s-MacBook-Pro:demo jscherman$ mongo --port 27018 < init/mongodb-init-dev
MongoDB shell version v4.0.3
connecting to: mongodb://127.0.0.1:27018/
Implicit session: session { "id" : UUID("31e9f04c-4a7b-474d-ac18-93f0fb725c86") }
MongoDB server version: 4.0.3
switched to db demo_db
true
{
    "acknowledged" : true,
    "insertedIds" : [
        "node-1",
        "node-2",
        "node-3",
        "node-4",
        "node-5"
    ]
}
bye

知道为什么会这样吗?提前谢谢。

EN

回答 2

Stack Overflow用户

发布于 2019-01-24 02:53:53

use my_db不是有效的JavaScript语法。从mongodb脚本中删除use my_db,并在build.gradle中添加“my_db”,并删除“<”,如下所示:

代码语言:javascript
复制
commandLine 'mongo', '--port', '27018', 'my_db', 'init/mongodb-init-dev'

顺便说一下,您可以看到更多的消息--info,即gradle --info init_dev来查看其他信息。

票数 0
EN

Stack Overflow用户

发布于 2019-05-08 19:02:00

这是因为没有配置输出。Gradle利用输入和任务的输出来确定任务是否需要执行。这是为了检查任务是否是最新的.

在这里读更多。tasks.html

若要解决问题,请按以下方式更新任务:

代码语言:javascript
复制
task init_dev {
doLast {
    exec {
        workingDir '.'
        commandLine 'mongo', '--port', '27018', '<', 'init/mongodb-init-dev'

        ext.output = {
            return standardOutput.toString()
        }
    }
}

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54333075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档