jenkins - 如何解决“无法获取未知属性'sourceJar”
问题描述
我使用 Gradle 在 Jenkins 中构建项目。但是在执行作业时,它会输出“Could not get unknown property 'sourceJar' for object of type org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication”错误。我对这个错误一无所知。
错误:
+ gradle projects
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* Where:
Build file '/home/jenkins/workspace/QWASP/RELEASE_BUILD_COMMON_QA/processing-common/build.gradle' line: 34
* What went wrong:
A problem occurred evaluating root project 'processing-common'.
> Could not get unknown property 'sourceJar' for object of type org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication.
脚本:(这是一个 bash 脚本;Gradle 版本 5.0)
PATH=$PATH:/opt/gradle/gradle-5.0/bin/gradle
git clone -b $Git_Branch git@git.zone24x7.lk:QWASP/processing-common.git
cd processing-common/
echo "`git tag`"
gradle projects
#./gradlew clean build tag publish -Prelease -P${release_type} -PmavenSettingsLocation='/opt/.m2/qv2.settings.xml' -PnexusUrl='https://nexus.zone24x7.lk/repository/releases'
if [ ! -z "${bump_component}" -a "${bump_component}" != "none" ]; then
./gradlew clean build tag publish -Prelease -PbumpComponent=${bump_component} -P${release_type} -PmavenSettingsLocation='/opt/.m2/qv2.settings.xml' -PnexusUrl='https://nexus.zone24x7.lk/repository/releases' -x test
else
./gradlew clean build tag publish -Prelease -P${release_type} -PmavenSettingsLocation='/opt/.m2/qv2.settings.xml' -PnexusUrl='https://nexus.zone24x7.lk/repository/releases' -x test
fi
echo "`git tag`"
git push --tags
cd ..
build.gradle 文件(错误说问题在第 38 行,即“artifact sourceJar”行)
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'net.linguica.gradle:maven-settings-plugin:0.5'
}
}
plugins {
id "org.sonarqube" version "2.7.1"
}
allprojects {
group 'com.zone24x7.qwasp.common'
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'idea'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'net.linguica.maven-settings'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
version = rootProject.version
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourceJar
artifact packageJavadoc
}
}
repositories {
maven {
// change to point to your repo, e.g. http://my.org/repo
name = 'nexus'
url project.hasProperty('nexusUrl') ? project.property('nexusUrl') : 'https://nexus.zone24x7.lk/repository/snapshots'
}
}
}
mavenSettings {
userSettingsFileName = project.hasProperty('mavenSettingsLocation') ? project.property('mavenSettingsLocation') : '/opt/.m2/qv2.settings.xml'
}
javadoc {
source = sourceSets.main.allJava
classpath = configurations.compileClasspath
options {
setMemberLevel JavadocMemberLevel.PUBLIC
setAuthor true
links "https://docs.oracle.com/javase/8/docs/api/"
}
}
task sourceJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allJava
}
task packageJavadoc(type: Jar) {
from javadoc
classifier = 'javadoc'
}
jacocoTestReport {
reports {
xml.enabled true
}
}
plugins.withType(JacocoPlugin) {
tasks["test"].finalizedBy 'jacocoTestReport'
}
}
解决方案
推荐阅读
- google-apps-script - 如何使用 Google Apps 脚本强制图像出现在预先指定的文本行中?
- ios - 当应用程序终止/终止时,如何快速调用服务以进行新更新
- javascript - 嵌套 svg 组“g”内的输入字段
- python - python类中的字典被视为静态对象?
- google-apps-script - 如何根据条件正确更新单元格?
- javascript - getusermedia 支持哪些设备
- sql - 来自匿名列 mssql 的条件
- google-cloud-platform - GCP:HTTP(S) 负载平衡后端服务区域选择
- android - 内部 Beta 测试应用程序在 Google Play 上显示警告消息
- android - Kotlin 用户能够与文本字段交互