我正在为一个项目设置 CI 模型。这个项目大约有 500 个模块。我们每次通过 CI 工具更新工作区并构建实际更改的模块。我们正在使用 gradle 构建所有模块,我的要求是仅将当前构建中更改的那些模块发布到 nexus 快照存储库。我知道有 gradle 任务来发布工件,但只发布到更改的模块是要求。
下面是示例。
A
B
C
D
E
F
如果 B 和 F 发生变化,那么我只想在 nexus 中发布 B 和 F 模块,如果 A 和 F 发生变化,则只发布 A 和 F 模块。
类似的东西
class IncrementalReverseTask extends DefaultTask {
@InputDirectory
def File inputDir
@OutputDirectory
def File outputDir
@TaskAction
void execute(IncrementalTaskInputs inputs) {
if (!inputs.incremental)
project.delete(outputDir.listFiles())
inputs.outOfDate { change ->
def targetFile = project.file("$outputDir/${change.file.name}")
targetFile.text = change.file.text.reverse()
}
inputs.removed { change ->
def targetFile = project.file("$outputDir/${change.file.name}")
if (targetFile.exists()) {
targetFile.delete()
}
}
}
}
我尝试了以下方式并遇到了这个问题
publishing {
publications {
maven(MavenPublication) {
groupId 'com.example'
artifactId 'core'
version '1.0-SNAPSHOT'
from components.java
}
}
repositories {
maven {
credentials {
username "abcde"
password "***********"
}
url "https://nexus.test.com/content/repositories/snapshots"
}
}
}
task incrementalPublishToMavenRepository(type: IncrementalPublishToMavenRepository) {
inputDir = file('.')
publication = project.tasks.getByPath(":${project.name}:publishMavenPublicationToMavenRepository").publication
}
class IncrementalPublishToMavenRepository extends org.gradle.api.publish.maven.tasks.PublishToMavenRepository {
@InputDirectory
def File inputDir
@OutputDirectory
File generatedFileDir = project.file("${project.buildDir}/libs")
@TaskAction
void perform(IncrementalTaskInputs inputs) {
println 'hello this should be executed ones'
}
}
并低于错误
gradle jar incrementalPublishToMavenRepository
Configuration on demand is an incubating feature.
:core:compileJava UP-TO-DATE
:core:processResources NO-SOURCE
:core:classes UP-TO-DATE
:core:jar UP-TO-DATE
:app:compileJava UP-TO-DATE
:app:processResources UP-TO-DATE
:app:classes UP-TO-DATE
:app:jar UP-TO-DATE
:app:generatePomFileForMavenPublication
:app:incrementalPublishToMavenRepository FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:incrementalPublishToMavenRepository'.
> The 'repository' property is required
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.