I have 2 maven modules. One module builds bunch of zip files using maven-assembly-plugin. Second module needs to include some of the zip files built by the first module in its package. What is the way to do this. Thank you.
The easiest thing would be to deploy the zips to a repository. For the local repository use install:install-file and for central repositories use deploy:deploy-file.
You can declare the zips as dependencies in your second module.
So someone else mentioned to deploy it to your repository. If you're already setup to deploy built artifacts to a repository this is easy, if not, check out http://maven.apache.org/plugins/maven-deploy-plugin/
Next, you need to use a plugin to get the zip file checked out of the repository. You could use shade, or the maven-dependency-plugin. Let's assume maven-dependency-plugin http://maven.apache.org/plugins/maven-dependency-plugin/usage.html
So add this to your maven pom file in the plugins section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>my.artifact.group.id</groupId>
<artifactId>my-artifact</artifactId>
<version>My-version</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/see</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Obviously you need to change the specifics of the artifact. That will unzip your zip file into target/see. If you want the actual zip file (which seems like what you were asking for but it's not clear), just change the goal from "unpack" to "copy-dependencies". You might also have to remove the outputDirectory or change some other bit of the configuration. Just play with it to get it where you need it, and see the page on the maven-dependency-plugin I mentioned above for more details.
Hope that helps.
Related
I would like to know if it is possible to set up a rule that marks a generated sources folder as generated sources root in Intellij Idea automatically.
Usually, Intellij detects the target/generated-sources directory as generated sources. My problem is that I also need it to automatically recognize the directory target/generated as generated sources, which Intellij never did in my case.
This is because of a maven plugin that I use for generating code from XSD schema:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-plugin</artifactId>
<version>${cxf.version}</version>
<configuration>
<extensions>
<extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:${cxf.version}</extension>
</extensions>
</configuration>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>xsdtojava</goal>
</goals>
<configuration>
<xsdOptions>
<xsdOption>
<xsd>src/main/resources/schema.xsd</xsd>
<packagename>org.example.project.common.request</packagename>
</xsdOption>
</xsdOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
For some reason, this plugin generates code into the target/generated directory, and not into the target/generates-sources, of which I read that it is the convention and the default from many points of view.
I've tried searching on the web with similar keywords like in the title, but this was the closest solution to what I wanted to achieve. And even this solution doesn't solve my problem because Intellij doesn't allow setting some path patterns; it only offers a few options that don't include target/generated directory.
Another solution suggests changing the target output, which I can't do in every single project I work on; that is not a solution either.
This is important to me because I work with many projects, and sometimes when my code builds with maven but doesn't compile with Intellij I forget to check whether I marked all the generated folders as sources, or I don't even know there are generated sources in the project.
Does someone know a way I can achieve that Intellij automatically detects source files in target/generated directory?
I got a liferay-portlet-project with a sample application/portlet that I want to become an archetype. Inside the project there is a folder containing two *.launch files to redeploy the webapp. Both have the following line which I have trouble with:
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/rawportlet}"/>
where "rawportlet" is the project's name. If I change it manually to ${artifactId} this variable is not resolved when using the archetype to create a project. Resolving this variable during project-generation would be nice.
Is there a way to achieve this? Or a workaround? Thanks in advance for your help.
Workaround: write a maven goal that the user can run after using the archetype. So the steps would be (for example):
generate project from archetype
mvn archetype:generate -DarchetypeCatalog=local
do some post-generation cleanup (execute in project's base dir)
mvn antrun:run
So my code for this is in "pom.xml" in the archetype:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<replace token= "rawportlet" value="${artifactId}" dir="runConfigs">
<include name="**/*.launch"/>
</replace>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
The "runConfigs" directory is where the *.launch files are stored.
Credits to:
Full search and replace of strings in source files when copying resources
Maven, configure specific goal
I have this same problem, and I used a different solution that works okay (but isn't perfect either).
Use value="${workspace_loc}/${artifactId}" in your launch config.
This will work as long as people do an archetype:gen at the workspace root. This works better for me than the selected answer because running that post processing requires another launch configuration (which somewhat defeats the whole purpose).
I have a maven project in which I would like to unpack all the child modules of a mutli module project. Does anyone know if the best way to approach this? There are over 100 modules in this project and I'm trying to avoid having to copy all this information somewhere else.
First you will need to create a pom.xml file that has all the projects as dependencies.
If there is one submodule that has
all other submodules as
dependencies, then you are in luck, just add a dependency to that submodule.
If not, you will have to write a script or program that gathers the groupIds, artifactIds, versions (and packagings) of all the submodules. And creates a pom.xml with all of them as dependencies.
Then, in this project, you can use dependency:unpack-dependencies to unpack the projects:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-projects</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>com.basegroupId*</includeGroupIds>
</configuration>
</execution>
</executions>
</plugin>
(Set includeGroupIds to a pattern that matches all submodule groupIds)
Now you just have to call
mvn generate-sources
(or any other phase you configure in the execution)
In my project , there is a spring XML config that utilizes ehcache to cache method returns.
xml snippet :
http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd
<ehcache:config configLocation="classpath:ehcache.xml"/>
<ehcache:proxy id="explainRetriever" refId="explainRetrieverImpl">
<ehcache:caching methodName="get*" cacheName="explainCache"/>
</ehcache:proxy>
but in runtime , server complains it cannot find definitions of http://www.springmodules.org/schema/ehcache , I know I have to add "spring-modules-cache.jar" to WEB-INF/lib directory.
But my project is maintained by maven , if I add "spring-modules-cache" to the runtime dependency , it will bring a lot of dependencies to my WAR file , filling my WAR with a lot of unnecessary jars. I just need one declaration in it , not all of its dependencies ...
Is there any way to tell maven not to include its dependencies to the project ?
Or ... another way , when packaging WAR , just copy another prepared spring-modules-cache.jar to WEB-INF/lib , how to do this ? Thanks !
As mentioned, you can use the exclusions mechanism, but that basically means excluding every runtime dependency declared in the dependency's pom, which is not only a pain, but fragile, since you have to keep tracking the dependency's pom to keep your list of exclusions up to date.
An alternative is to mark the dependency as <scope>provided</scope> and then copy the dependency yourself to the war construction directory under 'target' using the dependency:copy plugin goal. By default a war is built in
${project.build.directory}/${project.build.finalName}. See the war plugin for details.
E.g.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.springmodules</groupId>
<artifactId>spring-modules-cache</artifactId>
<version>0.8</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Have a look at this article - basically you need to use exclusions.
I have a multi-module project and I want to deploy on the project's site an HTML version of my source code using the JXR maven plugin.
The problem is that the JXR plugin runs well, the XREF folder is properly generated for each of my module, but when I use the mvn site:stage command in order to retrieve all the project's site content and to have all link properly generated it does not retrieve the XREF folders.
Here is an extract of my POM file where the JXR plugin is configured:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jxr-maven-plugin</artifactId>
<configuration>
<aggregate>true</aggregate>
</configuration>
</plugin>
Here is the command I use to create and stage my site:
mvn site site:stage
Do you guys have any idea?
Thanks in advance.
r.
Not sure this is relevant, but your command is running the site twice, mvn site will generate the site, and site:stage will also run the site, perhaps this is causing problems but I honestly can't see why.
Looking at the JXR documentation, it only mentions the site:site goal, I can't see why it wouldn't be run properly for the site:stage goal as it extends it. If you run the site goal, then copy the output to another directory, run the site:stage goal and compare the output it might give some insight into the problem.
Update: I tried this myself and the xref was included and aggregated nicely in c:\test\stage with the cross references correctly managed. I've included the configuration I used.
In my parent pom I defined the site configuration like this:
<build>
<plugins>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>stage</goal>
</goals>
</execution>
</executions>
<configuration>
<stagingDirectory>c:\test\stage</stagingDirectory>
</configuration>
</plugin>
</plugins>
</build>
The distributionManagement section was configured with the site information (not really needed as I set the stagingDirectory above, but the goal won't run without it).
<distributionManagement>
<site>
<id>mojo.website</id>
<name>Mojo Website</name>
<url>scp://test/</url>
</site>
</distributionManagement>
My JXR configuration in the parent pom was as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<reportSets>
<reportSet>
<id>src-xref</id>
<reports>
<report>jxr</report>
</reports>
</reportSet>
<reportSet>
<id>test-xref</id>
<reports>
<report>test-jxr</report>
</reports>
</reportSet>
</reportSets>
<configuration>
<aggregate>true</aggregate>
</configuration>
</plugin>
The commandline run was mvn clean site:stage
Edit: Per the comments, there is a codehaus jxr plugin with slightly different semantics. Be sure to use the org.apache.maven.plugins version rather than the org.codehaus.mojo version.