我正在使用gradle 4.10.2和IntelliJ IDEA Community Edition 2018.2 请注意,这是一个詹金斯共享库项目,因此与standard gradle project structure不同。
图像中显示的项目是现有的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)
答案 0 :(得分:0)
等级groovy plugin
期望资源默认为src/main/resources
。如果资源位于其他文件夹中,则应在sourceSets
中进行配置。如果您的资源文件也与src
文件夹一起使用,则可以尝试以下操作。
sourceSets {
main {
groovy {
srcDirs = ['src']
}
resources {
srcDirs = ['src']
}
}
test {
groovy {
srcDirs = ['test/groovy']
}
resources {
srcDirs = ['test/groovy']
}
}
}