Maven - 部署:在$ {project.build.directory}内的一系列文件上部署文件(目标/)

时间:2011-07-15 22:00:42

标签: java maven deployment wsdl kuali

我的情况快速简报 - 我正在开发一个代码库,它具有JAX-WS带注释的接口/类,我们从中生成代码优先的wsdls。我们正在使用CXF的cxf-java2ws-plugin在maven内构建时生成wsdl,以包含在为每个模块生成的.jar中。

我们要做的是将这些wsdl文件部署到maven存储库,因为maven存储库可以充当

  • 临时服务存储库(如描述here
  • 通过指向wsdl的maven坐标而不是自己管理wsdl文件,为客户提供了一种简单的方法来使用cxf codegen plugin

到目前为止我得到的是一个使用依赖项的pom文件:unpack-dependencies将项目中的所有wsdl文件放入此模块中的一个目录$ {project.build.directory}(通常称为目标/对那里的每个人)。

我不知道该怎么做是遍历每个文件并在每个wsdl上调用deploy:deploy-file mojo。我有什么选择,因为我真的想要自动化部署这些wsdl文件的过程而没有人手动部署它们?

为了完整起见,这是pom文件:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>rice</artifactId>
        <groupId>org.kuali.rice</groupId>
        <version>2.0.0-m7-SNAPSHOT</version>
    </parent>
    <artifactId>rice-dist-wsdl</artifactId>
    <name>Rice WSDL Distributions</name>
    <packaging>pom</packaging>

    <properties>
        <wsdl.location>${project.build.directory}/wsdl</wsdl.location>
    </properties>


    <!-- Depends on all API modules and modules that generate or contain wsdls -->
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-core-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-kew-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-kim-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-krms-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-ksb-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-shareddata-api</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-wsdls</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includes>**\/*.wsdl</includes>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

推送目标/ wsdl中的wsdl(它们包含在每个.jar所依赖的wsdl /中):

[whaley@sunspot ~/Repositories/Kuali/rice/dist-wsdl] 
> find . -iname '*.wsdl' | head -3
./target/wsdl/CampusService.wsdl
./target/wsdl/CountryService.wsdl
./target/wsdl/CountyService.wsdl

解决方案

我认为我实施的内容与Ryan Steward提供的答案不同,我接受了他的答案,因为它让我自己写了。

基本上,这是一个maven pom,它是上述多模块项目中的一个子模块。我正在使用依赖:unpack-dependencies,然后使用内联groovy脚本在每个wsdl文件上调用deploy:deploy-file。这有点像hackjob,但我想不出一个更好的方法来做到这一点,没有硬编码模块中的wsdl文件的路径,并调用几个deploy:deploy-file mojo执行,导致非常详细POM。

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>rice</artifactId>
        <groupId>org.kuali.rice</groupId>
        <version>2.0.0-m7-SNAPSHOT</version>
    </parent>
    <artifactId>rice-dist-wsdl</artifactId>
    <name>Rice WSDL Distributions</name>
    <packaging>pom</packaging>

    <properties>
        <wsdl.location>${project.build.directory}/wsdl</wsdl.location>
    </properties>


    <!-- Depends on all API modules and modules that generate or contain wsdls -->
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-core-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-kew-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-kim-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-krms-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-ksb-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>rice-shareddata-api</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-wsdls</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includes>**\/*.wsdl</includes>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>deploy</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>
                                def repo_url
                                def repo_id
                                if ("${project.version}".endsWith("SNAPSHOT")) {
                                    repo_url = "${kuali.repository.snapshot.url}"
                                    repo_id = "${kuali.repository.snapshot.id}"
                                } else {
                                    repo_url = "${kuali.repository.release.url}"
                                    repo_id = "${kuali.repository.release.id}"
                                }

                                def wsdlGroupId = "${project.groupId}.wsdl"
                                new File("${wsdl.location}").eachFile() { file ->
                                    serviceName = file.name.split("\\.")[0]

                                    log.info("Deploying ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}")

                                    execString = "mvn deploy:deploy-file -Dfile=${file} -Durl=${repo_url} -DrepositoryId=${repo_id} "
                                    execString += "-DgroupId=${wsdlGroupId} -DartifactId=${serviceName} "
                                    execString += "-Dversion=${project.version} -Dpackaging=wsdl -Dclassifier=wsdl"

                                    def proc = execString.execute()
                                    proc.waitFor()

                                    err = proc.err.text
                                    if (err != null &amp;&amp; err.length() > 0) {
                                        log.error(err)
                                        fail("Deployment failed for ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}.  \n Run in verbose mode for full error.")
                                    } else {
                                        log.info("Successfully deployed ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}")
                                    }
                                }
                            </source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

2 个答案:

答案 0 :(得分:2)

Build Helper插件可能会帮助你。你可以让它发布WSDL,但你必须明确列出每一个,并且它们都会在你的名字中有你的pom的artifactId。只有分类器才能改变。例如:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>attach-WSDLs</id>
            <phase>package</phase>
            <goals>
                <goal>attach-artifact</goal>
            </goals>
            <configuration>
                <artifacts>
                    <artifact>
                        <file>${project.build.directory}/foo.wsdl</file>
                        <classifier>foo</classifier>
                        <type>wsdl</type>
                    </artifact>
                    <artifact>
                        <file>${project.build.directory}/bar.wsdl</file>
                        <classifier>bar</classifier>
                        <type>wsdl</type>
                    </artifact>
                </artifacts>
            </configuration>
        </execution>
    </executions>
</plugin>

如果您的pom坐标是myGroupId:myArtifactId:1.1.1,那么使用此配置安装和部署的工件将命名为myArtifactId-1.1.1-foo.wsdl和myArtifactId-1.1.1-bar.wsdl。这是我所知道的最好的。

答案 1 :(得分:2)

另一种可能性:Maven Ant任务可以deploy files。我从来没有使用它,但我敢打赌你可以使用antrun配置和一些ant模式匹配来获取和部署所有的WSDL。