Dmitry Senkovich
Dmitry Senkovich

Reputation: 5921

Unpack wsdl schema from dependencies in Gradle

I've got the following plugin configuration in a Maven (for now) project:

<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>

Unfortunately, I can't find something similar in Gradle. The only thing I've found is creating a task, loading artifacts as zip files (specifying the whole path to the artifact) and then unzip it.

Is there any other alternative? Thank you very much for any help!

Upvotes: 1

Views: 518

Answers (2)

Louis Jacomet
Louis Jacomet

Reputation: 14500

Here is another way, that is closer to Gradle best practices:

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
}

The benefit is that there is a clear split between where the files are coming from (repositories), which files (dependencies) and what to do with them (task definition).

Upvotes: 1

Dmitry Senkovich
Dmitry Senkovich

Reputation: 5921

Eventually, I ended up with the following task:

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'
    }
}

Hope it help someone

Upvotes: 0

Related Questions