Maven - expand: expand a file over a series of files in $ {project.build.directory} (target /)

Quick briefing on my situation. I am working on a code base that has JAX-WS annotated interfaces / classes from which we generate the first wsdls with code. We use the CXF cxf-java2ws-plugin to generate wsdls during build in maven to include in the .jar created for each module.

What we need to do is deploy these wsdl files to the maven repository, since the maven repository can act as

  • temporary service repository (e.g. described here )
  • provide customers with an easy way to use the cxf codegen plugin by pointing to the maven coordinates for wsdl instead of managing the wsdl files themselves

What I still have is a pom file that uses the dependency: unpack-dependencies to get all the wsdl files in a project into one directory in these modules $ {project.build.directory} (usually known as target / to everyone there).

What I don’t know how to do is skip each of these files and call deploy: deploy-file mojo on each wsdl. What are my options here since I really want to automate the process of deploying these wsdl files and not use them manually manually?

For completeness, here is the pom file:

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

What forces wsdls to target / wsdl (they are contained inside wsdl / inside each .jar depends on):

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

Decision

The thought of what I realized was different from Ryan Steward's accepted answer, I accepted his answer because it made me write my own.

Basically, here is maven pom, which is a submodule in the multi-module project described above. I use the dependency: unpack-dependencies, and then using the built-in groovy script to call deploy: deploy-file in each of these wsdl files. This is a bit of a hack, but I could not think of a better way to do this without the hard-coding path to the wsdl files in the module and call several deployment executions: deploy-file mojo on them, which leads to a very detailed point.

 <?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> 
+6
source share
2 answers

Another possibility: Maven Ant tasks can deploy files . I never used it, but I bet you could use the antrun configuration and several Ant patterns to pick up and deploy all the WSDLs.

+2
source

The Build Helper plugin can help you. You can publish WSDL, but you will have to specify each of them explicitly, and all of them will have an artifact of your pom in their names. Only the classifier can change. For instance:

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

If your pom coordinate is myGroupId: myArtifactId: 1.1.1, then artifacts set and deployed using this configuration will be called myArtifactId-1.1.1-foo.wsdl and myArtifactId-1.1.1-bar.wsdl. This is the best I know.

+2
source

Source: https://habr.com/ru/post/892865/


All Articles