Intellij Idea ignores maven assembly plugin - maven

I have a multimodule project and one module is a web app and the second one has a custom assembly.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>src</descriptorRef>
</descriptorRefs>
<formats><format>jar</format></formats>
</configuration>
<executions>
<execution>
<id>cfg-src</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
Basically I need this archive to contain maven project with sources and maven structure, no binaries etc.
When I assemble WAR with maven i.e. mvn package, everything is fine. I use "src" classifier in dependcy. My WAR contains the jar with correct assembly. But when I deploy WAR with Intellij Idea (I created tomcat run config) assembly config of the project is ignored and I an incorrect one. How do I make Idea not to ignore assembly plugin. Please let me know if I'm clear.

IntelliJ does not run mvn package when you deploy your webapp in Tomcat. It runs its custom Make and Build artifact actions.
You can change this behavior by going into Run/Debug configurations dialog and setting Run Maven Goal (package in your case) as a Before launch action instead of Make and Build artifact.
Hope this helps

Related

Maven: properties-maven-plugin not generating properties files in IntelliJ builds

How do you get IntelliJ maven projects to build in intelliJ and produce the xxx.properties file configured in the pom.xml?
I have to run a command-line mvn package for the properties file to get produced, and only then executions run inside IntellIJ run configurations are able to observe the file.
If i simply compile, the properties file is not produced, and IntelliJ run configurations are not able to observe the file (properties file not found).
It seems that IntelliJ is only running compile during builds...
I have a multi-module scala project being built with Maven. In the base pom in the I have added:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>write-project-properties</goal>
</goals>
<configuration>
<outputFile>${project.build.outputDirectory}/xxx.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
When i run mvn package, the target/classes/ folder of each module gets an xxx.properties file written into it. If I run an IntelliJ run configuration after this, all is well, the file is found.
If I mvn clean and only build the project using IntelliJ's build process, this file is NOT produced, and at execution time the file is not found. :(
This plug-in is not supported by IntelliJ IDEA build system yet.
The workaround is to delegate the build to Maven.

how to Include source code inside the mvn built jar

We are changing our projects from ant to mvn build.
In the ant build jar - xyz.jar [we used to have the source files inside]
xyz.sources.jar inside xyz.jar
How can I do the same through pom.xml. I tried maven-source-plugin, but this creates the sources jar inside target folder. I want this sources jar inside output jar.
Thanks.
The convention is to ship these artifacts separately. Offering them separately in a Maven repository allows tools like Eclipse and IntelliJ to match the sources to the binaries automatically, and life is good.
To do what you want to do, you could run the Maven Source Plugin before the main JAR file is packaged (e.g. in the prepare-package phase), and have it write the sources JAR to the target/classes/ folder, and not attach. Like so:
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>source-jar</id>
<goals>
<goal>jar</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<finalName>filename-of-generated-jar-file</finalName>
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>

how to wildcard attach multiple files to an artifact in maven?

In my maven project, the ant plugin generate multiple war files and I want to attach them all in the same artifact. I tried the build-helper-maven-plugin like this
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/*.war</file>
<type>war</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
I don't want to specify each war file separately because the ant plugin is dynamic. Is there a way to do that?
Thanks,
Providing wildcards for single artifacts does not seem to be supported by the Build Helper plugin (btw, if it did, it would likely use the includes/excludes configuration used by Resources Plugin).
I've learned that, if you choose to use Maven, it's best to just adjust your build to "the Maven way."
In this case, you should revise your build to not use the ant war plugin, and instead have a multi-module build with a separate module (sub-project) for each war file.
Alternatively, in the past I have accomplished something like you are doing via the Maven Assembly plugin, where the wars are all shipped together in a single tar/gz file. The archive (which contains each of the wars) is then attached to the build.
Note that you should prefer to have your "web apps" module have a artifact type of "pom." The assembly plugin will attach the archives to the final build.
For more information, I've found that Sonatype's online books are a great resource:
http://www.sonatype.com/Support/Books

Maven Multi Module Project + root pom plugin

I have a maven multi module project why is it when I put this configuration:
<plugin>
<groupId>org.zeroturnaround</groupId>
<artifactId>jrebel-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<id>generate-rebel-xml</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
in the root pom and mvn install the project no rebel.xml file is generated.
I can generate it using mvn org.zeroturnaround:jrebel-maven-plugin:1.1.3:generate but that only creates the rebel.xml under target/classes and does not include it in the jar\war package.
But when I put the above configuration in the individual maven module it does generate it during install and includes it in the package as per process-resources
But I don't want to duplicate the plugin in all modules, but only put it in the root pom and during install is should generate the rebel.xml file and include in the package.
Am I missing how maven works?
Turns out it was my bad I had put the plugin by error in the pluginManagement section when I thought I had put it in the build>plugins section where it should be, now it's working fine. Many Thanks

Maven war plugin

Is it possible to have the maven war plugin output to two different locations? I currently have the following in my pom.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
This was already existing in the POM for the gwt maven archetype, and I'm guessing this explodes everything into the webappDirectory(which the gwt plugin then uses for it development mode).
When I do a
mvn war:war
It generate a war file for me in the target directory. So, I suspect its a different plugin configuration than the one in my POM (default behaviour?). How do I override this?
I basically want to accomplish the following:
I would like to have two different resource folders "src/resources/a" and "src/resources/b" , and have one of the folders used in the exploded version (currently in my pom) and the other version used when I do a "mvn war:war"
Per this question How to execute maven plugin execution directly from command line?, Maven doesn't use pom configuration when you invoke a plugin directly (e.g. mvn war:war). Your POM config is telling Maven to run the exploded goal when the compile phase is invoked (i.e when you run mvn [phase] where phase is compile or later).
I suggest you investigate using a separate profile for exploded deployment (called eg exploded), with a different configuration of the resources plugin to copy a different resources directory. Then use mvn compile -Pexploded for the exploded version.

Resources