[英]sourcesJar task in gradle 5
我继承了一个代码库,我怀疑它最初是用 Gradle 4 构建的(但我不确定)。 我正在使用 Gradle 5.5.1,当我运行gradle
时,出现与发布到 Maven 存储库有关的错误:
* What went wrong:
A problem occurred evaluating root project 'common'.
> Could not find method sourcesJar() for arguments [build_d1u03z05r8d12r3e8b5qq1fxm$_run_closure3$_closure13$_closure15$_closure16@190bc2b8] on object of type org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication.
将 sourcesJar 任务添加到自定义 Gradle 插件看起来像一个类似的问题,但它是一个不同的错误,他们的解决方案无论如何都不起作用。
我的 build.gradle 的相关部分是:
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar {
classifier "sources"
}
artifact testJar {
classifier "tests"
}
}
}
repositories {
maven {
url 'http://repo.url'
credentials {
username "$username"
password "$password"
}
}
}
}
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
task testJar(type: Jar) {
from sourceSets.test.output
classifier = 'tests'
}
好的,我想我想通了: https ://docs.gradle.org/5.5.1/userguide/publishing_maven.html#publishing_maven: deferred_configuration说在 Gradle 4 中的项目的其余部分之后执行了publishing
块,但不是在 Gradle 5 中。
所以,改变
artifact sourcesJar {
classifier "sources"
}
artifact testJar {
classifier "tests"
}
到
afterEvaluate {
artifact sourcesJar {
classifier "sources"
}
artifact testJar {
classifier "tests"
}
}
让我更进一步。 有了这个改变,我得到了这个错误:
* What went wrong:
A problem occurred configuring root project 'common'.
> Cannot create a Publication named 'sourcesJar' because this container does not support creating elements by name alone. Please specify which subtype of Publication to create. Known subtypes are: MavenPublication
https://discuss.gradle.org/t/cannot-create-a-publication-named-x/3726和Gradle:在自定义独立插件中使用 'maven-publish' 插件似乎暗示了项目的前缀。 应该修复它。
所以把它改成:
afterEvaluate {
artifact project.sourcesJar {
classifier "sources"
}
artifact project.testJar {
classifier "tests"
}
}
似乎工作,虽然我对这个项目有点不确定。 字首。
在我的情况下,我必须添加以下内容,Gradle 知道这些工件:
java {
withJavadocJar()
withSourcesJar()
}
然后我就可以这样使用它:
publishing.publications {
mavenJava(MavenPublication) {
from components.java
}
}
Javadoc 以及 Sources 已发布。 似乎没有必要添加afterEvaluate
块。
在这个块中:
artifact sourcesJar {
classifier "sources"
}
artifact testJar {
classifier "tests"
}
移除闭包……让它看起来像这样:
artifact sourcesJar
artifact testJar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.