jenkins - 无法在Gradle项目中加载资源

标签 jenkins gradle jenkins-pipeline

我正在使用gradle 4.10.2和IntelliJ IDEA Community Edition 2018.2
请注意,这是一个jenkins共享库项目,因此与standard gradle project structure不同。
enter image description here

图像中显示的项目是现有的Gradle项目。我只是试图加载属性文件,即。 Groovy类EmailTemplate中的mailTemplate.properties,但问题是无论我将其保存在何处(如图中所示),都不会加载它。我创建了一个单独的测试gradle项目,并将其放置在默认(src / main / resources)目录中。它像微风一样工作。
我尝试在两个地方创建“资源”,但徒劳无功。

build.gradle是:

buildscript {
    repositories {
        ivy {
            url "$repositoryURL/$resolveRepository"
        }
        maven {
            url "$repositoryURL/$resolveRepository"
        }
    }
    dependencies {
        classpath "tools.gradle.plugin:ReleasePlugin:1.10.0"
        classpath "tools.gradle.plugin:qualityreport:v1.14.4"
    }
}

group 'tools'

apply plugin: 'groovy'
apply plugin: 'tools.gradle.plugin.releaseplugin'
apply plugin: 'tools.gradle.plugin.qualityreport'

sourceSets {
    main {
        groovy {
            srcDirs = ['src']
        }
    }
    test {
        groovy {
            srcDirs = ['test/groovy']
        }
    }
}

repositories {
    addAll(buildscript.repositories)
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.15'
    compile 'org.codehaus.groovy:groovy-json:2.4.9'
    compile 'com.cloudbees:groovy-cps:1.1'
    compile 'org.slf4j:slf4j-api:1.7.21'

    testCompile 'junit:junit:4.12'
    testCompile 'org.hamcrest:hamcrest-core:1.3'
    testCompile 'net.bytebuddy:byte-buddy:1.6.4'
    testCompile ('org.spockframework:spock-core:1.1-groovy-2.4') {
        exclude group: 'org.codehaus.groovy'
    }
    testCompile gradleTestKit()
    testCompile group: 'com.lesfurets', name: 'jenkins-pipeline-unit', version: '1.1'
    testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
    testCompile group: 'tools.gradle.plugin', name: 'jenkins-shared-stages', version: 'v2.48.0'

    // jenkins dependencies
    testCompile 'org.jenkins-ci.plugins:script-security:1.34@jar'
}

task copySharedLibs(type: Copy, group: "PipelineTest") {
    from '.'
    into 'build/libs/jenkins-shared-pipelines@master'
    include 'src/**'
    include 'vars/**'
}

test.dependsOn(copySharedLibs)

最佳答案

Gradle groovy plugin期望资源默认为src/main/resources。如果资源位于其他文件夹中,则应在sourceSets中进行配置。如果您的资源文件也与src文件夹一起使用,则可以尝试以下操作。

sourceSets {
    main {
        groovy {
            srcDirs = ['src']
        }
        resources {
            srcDirs = ['src']
        }
    }
    test {
        groovy {
            srcDirs = ['test/groovy']
        }
        resources {
            srcDirs = ['test/groovy']
        }
    }
}

关于jenkins - 无法在Gradle项目中加载资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55492221/

相关文章:

mercurial - "hg"Jenkins Mercurial插件调用时找不到

jenkins - 在 jenkins 上查找作业的所有构建的环境变量

android - Gradle 错误使用 fbutton

git - Jenkins:从另一个存储库而不是我要构建的存储库加载 Jenkinsfile

jenkins - 列出 Jenkins 管道上工作区中的文件

jenkins - 如何在Jenkins的Pipeline脚本中执行SQL语句?

docker - 有条件地忽略 COPY 上的 .dockerignore 文件

android - 在android studio中创建新项目时出错

android - 找不到参数的方法 include() [ :app] on root project Android Studio

Jenkins 管道如何更改到另一个文件夹