小编Geo*_*ies的帖子

Gradle - 如果项目仍具有SNAPSHOT依赖项,则抛出异常

如果当前项目仍具有快照依赖项,我想使gradle构建失败.

到目前为止,我的代码只查找java依赖项,缺少.NET项,因此它只适用于java项目.我想让它适用于所有项目.

def addSnapshotCheckingTask(Project project) {
    project.tasks.withType(JavaCompile) { compileJava ->
        project.tasks.create(compileJava.name + 'SnapshotChecking', {
            onlyIf {
                project.ext.isRelease || project.ext.commitVersion != null
            }
            compileJava.dependsOn it
            doLast {
                def snapshots = compileJava.classpath
                        .filter { project.ext.isRelease || !(it.path ==~ /(?i)${project.rootProject.projectDir.toString().replace('\\', '\\\\')}.*build.libs.*/) }
                        .filter { it.path =~ /(?i)-SNAPSHOT/  }
                        .collect { it.name }
                        .unique()
                if (!snapshots.isEmpty()) {
                    throw new GradleException("Please get rid of snapshots for following dependencies before releasing $snapshots")
                }
            }
        })
    }
}
Run Code Online (Sandbox Code Playgroud)

我需要一些帮助,以便将此代码段生成适用于所有类型的依赖项(不仅仅是java)

谢谢!

LE可以这样的工作吗? https://discuss.gradle.org/t/how-can-i-check-for-snapshot-dependencies-and-throw-an-exception-if-some-where-found/4064

.net java groovy gradle

5
推荐指数
1
解决办法
207
查看次数

标签 统计

.net ×1

gradle ×1

groovy ×1

java ×1