Java 渐变依赖资源访问
如何从依赖项访问资源?我有这样的想法: 包装器项目build.gradleJava 渐变依赖资源访问,java,gradle,Java,Gradle,如何从依赖项访问资源?我有这样的想法: 包装器项目build.gradle .. dependencies { compile com.company:mysubproject1:2.0.1 compile com.company:mysubproject2:2.0.1 .. 这些子项目的资源目录中有一些文件,例如src/main/resources/liquibase/changelog.xml 这些子项目可能有n个,我需要我的gradle任务 通过所有依赖项,获取所有changel
..
dependencies {
compile com.company:mysubproject1:2.0.1
compile com.company:mysubproject2:2.0.1
..
这些子项目的资源目录中有一些文件,例如src/main/resources/liquibase/changelog.xml
这些子项目可能有n个,我需要我的gradle任务
通过所有依赖项,获取所有changelog.xml文件,并从中创建新文件,以供以后使用。实际上并不难:
doFirst {
println 'Generating master changelog...'
def changelogFiles = []
configurations.runtime.each {
def zip = new ZipFile(it)
def entries = zip.entries()
entries.findAll { entry -> entry.name.contains("liquibase") }
.findAll { entry -> entry =~ /changelog.xml/ }
.each { entry ->
changelogFiles.add(((ZipEntry) entry).name)
}
}
def resDir = sourceSets.main.output.resourcesDir.path + '/liquibase'
def changelogFile = new File("$resDir/changelog-master.xml")
changelogFile.write("<databaseChangeLog xmlns=\"http://www.liquibase.org/xml/ns/dbchangelog\"\n" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xsi:schemaLocation=\"http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd\">\n\n")
changelogFiles.each {
println("Including $it to changelog.")
changelogFile << " <include file=\"classpath:$it\"/> \n"
}
changelogFile << "\n</databaseChangeLog>"
}
doFirst{
打印“正在生成主变更日志…”
def changelogFiles=[]
configurations.runtime.each{
def zip=新ZipFile(it)
def entries=zip.entries()
entries.findAll{entry->entry.name.contains(“liquibase”)}
.findAll{entry->entry=~/changelog.xml/}
.每个{条目->
changelogFiles.add(((ZipEntry)条目).name)
}
}
def resDir=sourceSets.main.output.resourcesDir.path+'/liquibase'
def changelogFile=新文件($resDir/changelog master.xml)
changelogFile.write(“\n\n”)
changelogFiles.each{
println(“包括$it到changelog。”)
变更日志文件