Unpack wsdl schema from dependencies in Gradle

plugins

(Dmitry Senkovich) #1

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!


(Dmitry Senkovich) #2

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

(uklance) #3

You should do this via a configuration / dependencies rather than using maven local url.

Eg

configurations {
    wsdl { transitive = false}
} 
dependencies {
    wsdl 'foo:wsdl1:1.0'
    wsdl 'bar:wsdl2:2.0'
}
task copyWsdlFromArtifacts(type: Copy) {
    includeEmptyDirs = false
    configurations.wsdl.each { artifact ->
        from zipTree(artifact)
    } 
    into "$buildDir/schema/"
    include '**/*.xsd', '**/*.wsdl'
}

(Dmitry Senkovich) #4

Wow, that is cool! Thank you very much! Sorry, I’m just getting started with Gradle, we’re only considering migrating to Gradle.