我在Maven(现在)项目中有以下插件配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>initialize</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<includes>**/*.xsd,**/*.wsdl</includes>
<outputDirectory>${project.build.directory}/schema</outputDirectory>
<artifactItems>
<artifactItem>
<groupId>com.someCompany.someTeam.someProject</groupId>
<artifactId>someProject-wsdl</artifactId>
</artifactItem>
<artifactItem>
<groupId>com.someCompany</groupId>
<artifactId>someCompany-xsd</artifactId>
</artifactItem>
<artifactItem>
<groupId>com.someCompany.someTeam</groupId>
<artifactId>common-schema</artifactId>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
不幸的是,我在Gradle中找不到类似的东西。我发现的唯一一件事就是创建一个任务,将工件加载为zip文件(指定工件的整个路径)然后解压缩。
还有其他选择吗?非常感谢您的帮助!
答案 0 :(得分:1)
这是另一种方式,更接近Gradle最佳实践:
repositories {
mavenLocal()
}
configurations {
xsdSources { // Defined a custom configuration
transitive = false // Not interested in transitive dependencies here
}
}
dependencies {
xsdSources "com.someCompany.someTeam.someProject:someProject-wsdl:$someVersion"
xsdSources "com.someCompany.someTeam:otherArtifact:$otherVersion"
}
task copyWsdlFromArtifacts(type: Copy) {
from configurations.xsdSources.files.collect { zipTree(it)}
into "$buildDir/schema"
include '**/*.xsd', '**/*.wsdl'
includeEmptyDirs = false
}
好处是文件来自哪里(repositories
),哪些文件(dependencies
)以及如何处理它们(task
定义)之间存在明显的分歧
答案 1 :(得分:0)
最终,我最终完成了以下任务:
task copyWsdlFromArtifacts(type: Copy) {
includeEmptyDirs = false
def mavenLocalRepositoryUrl = repositories.mavenLocal().url
[
"${mavenLocalRepositoryUrl}/com/someCompany/someTeam/someArtifact/${someVersion}/someArtifact-${someVersion}.jar",
"${mavenLocalRepositoryUrl}/com/someCompany/someTeam/otherArtifact/${otherVersion}/otherArtifact-${otherVersion}.jar"
].each { artifact ->
from(zipTree(artifact))
into "$buildDir/schema/"
include '**/*.xsd', '**/*.wsdl'
}
}
希望有人帮助