从 Gradle 中的依赖项中解压 wsdl 模式
Unpack wsdl schema from dependencies in Gradle
我在 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 文件(指定工件的整个路径),然后将其解压缩。
还有其他选择吗?非常感谢您的帮助!
最终,我完成了以下任务:
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'
}
}
希望对大家有所帮助
这是另一种更接近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
) 之间有明确的区分定义)。
我在 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 文件(指定工件的整个路径),然后将其解压缩。
还有其他选择吗?非常感谢您的帮助!
最终,我完成了以下任务:
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'
}
}
希望对大家有所帮助
这是另一种更接近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
) 之间有明确的区分定义)。