当我将插件发布到自定义Artifactory存储库时,我想排除.svn
文件夹。我假设基于下面提供的错误跟踪记录,出现了.svn
文件夹的问题。
我正在使用以下命令发布:gradlew artifactoryPublish --stacktrace
这是build.gradle
中的发布块:
artifactory {
contextUrl = artifactory_context
publish {
repository {
repoKey = 'plugins-release-local'
username = artifactory_user
password = artifactory_password
maven = true
}
defaults {
publications ('mavenJava')
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
这是我尝试发布时获得的堆栈跟踪,请注意尝试将
.svn/entries
复制到assets/entries
。...
:copyAssets FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':copyAssets'.
> Could not copy file '/u01/var/build/pluginXYZ/grails-app/assets/.svn/entries' to '/u01/var/build/pluginXYZ/build/resources/main/META-INF/assets/entries'.
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':copyAssets'.
...
Caused by: org.gradle.api.GradleException: Could not copy file '/u01/var/build/pluginXYZ/grails-app/assets/.svn/entries' to '/u01/var/build/pluginXYZ/build/resources/main/META-INF/assets/entries'.
...
Caused by: java.io.FileNotFoundException: /u01/var/build/pluginXYZ/build/resources/main/META-INF/assets/entries (Permission denied)
... 80 more
entries
(两棵树)的权限均为-r--r--r--
。如果排除那些文件夹,则应该摆脱上述权限问题。第一次 checkout 将始终发布,但随后的发布(例如更新后)将失败,并显示此错误。
更新#2
这是我尝试失败的三种组合:
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
//first attempt
//exclude("**/.svn/**")
//second attempt
//exclude{ details -> details.file.name.contains(".svn") }
//third attempt
//exclude "**/.svn/**"
}
}
}
使用所有三种尝试发布时的错误输出如下:
Caused by: org.gradle.api.internal.MissingMethodException: Could not find method exclude() for arguments [build_3nsvrqvwahy23ir3fxdj970id$_run_closure7_closure13_closure14_closure15@10e9a5fe] on org.gradlpublish.maven.internal.publication.DefaultMavenPublication_Decorated@ca7e37f.
更新#3
我发现以下链接taking about excluding files。
然后,我将
gradle.build
调整为:publishing {
publications {
mavenJava(MavenPublication) {
from components.java {
exclude "**/.svn/**"
}
}
}
}
同样的错误。
更新#4
更多尝试...相同结果
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourceJar{
exclude '**/.svn/**'
}
}
}
}
要么
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact exclude '**/.svn/**'
}
}
}
最佳答案
假设您有一个文件,仅在发布到存储库时才要避免。如果按照@TekiusFanatikus的建议去
sourceSets {
main {
java {
exclude '**/.svn/**'
}
}
}
您将能够实现它,但这也将从使用gradle build生成的 Artifact 中排除文件/文件夹等。
相反,我建议使用此处提到的方法gradle documnetation
您可以创建一个应用了所需排除的任务
task apiJar(type: Jar) {
baseName "publishing-api"
from sourceSets.main.output
exclude '**/.svn/**'
}
然后在发布时引用任务。
publishing {
publications {
api(MavenPublication) {
groupId 'org.gradle.sample'
artifactId 'project2-api'
version '2'
artifact apiJar
}
}
}
这样,发布的jar将没有.svn文件夹。我想在这里指出的一点是,它不会碰到使用gradle build创建的 Artifact 。它将仍然具有您的.svn文件夹。
但是,如果您希望将其从两个地方都删除,那么最好的选择就是上面的建议。
关于gradle - 在插件发布期间排除文件和文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37171372/