【问题标题】:Don't see all gradle tasks when run on Jenkins在 Jenkins 上运行时看不到所有 gradle 任务
【发布时间】:2019-07-28 11:13:57
【问题描述】:

我正在使用 Gradle 作为构建系统的 xtext 项目。我想在 Jenkins 中运行 gradlew war,但是由于某种原因它不可用。当我运行gradlew tasks 以查看所有可用选项时,它没有在此处列出。这些是可用的任务:

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

Help tasks
----------
buildEnvironment - ...
...

但是当我在我的机器上本地运行它时,可用的任务要多得多:

Build tasks
-----------
...
war - Generates a war archive with all the compiled classes, the web-app content and the libraries.

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.

Help tasks
----------
...

IDE tasks
---------
...

Run tasks
---------
jettyRun - Starts an example Jetty server with your language

Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.

所以war 任务显然就在那里,我可以毫无问题地运行它。为什么詹金斯当时看不到它。我没有修改任何 Gradle 文件。所有都包含使用项目创建的默认代码。如果需要,我可以附加任何 Gradle 文件,但我不知道可能需要哪一个。然而,这是主要的 build.gradle 文件(子目录中还有更多:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.xtext:xtext-gradle-plugin:2.0.4'
    }
}

subprojects {
    ext.xtextVersion = '2.17.0'
    repositories {
        jcenter()
    }

    apply plugin: 'java'
    dependencies {
        compile platform("org.eclipse.xtext:xtext-dev-bom:${xtextVersion}")
    }

    apply plugin: 'org.xtext.xtend'
    apply from: "${rootDir}/gradle/source-layout.gradle"
    apply plugin: 'eclipse'

    group = 'ic.ac.uk.mydsl'
    version = '1.0.0-SNAPSHOT'

    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'

    configurations.all {
        exclude group: 'asm'
    }
}

编辑: 我在 git repo 中的父目录的图像:

【问题讨论】:

  • 您确定在向导中配置了 Web 项目。如果是,war 插件将应用于 .web 项目,因此 war 将在任务中可用。所以你确定你已经承诺了一切吗? (例如,设置等级)
  • 抱歉,我不知道什么是向导。但是,我在帖子中附加了我的 git repo 的图像。
  • 这看起来不错。但我不知道为什么它不应该工作。我已经看到这样做了 100 次并且它总是有效的。 => 无法访问复制示例:不知道。 => 它是否适用于 hello world mydsl 示例?
  • 我去试试
  • 所以我创建了一个新项目并且没有修改任何内容,jenkins 上的“gradlew tasks”仍然返回相同的列表,没有“war”任务。

标签: jenkins gradle


【解决方案1】:

您确定您在 Jenkins 和本地的同一目录中运行 ./gradlew tasks 吗?如果您从根项目目录运行 Gradle 命令,则将显示根项目的任务,但不会显示子项目的任何任务。您的根项目似乎没有应用任何插件,只有子项目这样做。因此,您的根项目中不会有任何插件特定的任务,例如 war

【讨论】:

  • 我很确定我在同一个目录中执行此操作,因为我搜索了我的项目并且只有一个 gradlew 文件,所以我认为无论如何都不可能从不同的目录运行它。如何在本地运行 Jenkins 子目录中的任务,因为它似乎会自动从子目录中找到任务?
猜你喜欢
  • 2022-06-22
  • 2014-06-04
  • 2020-09-06
  • 2020-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多