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.
Related
I added maven source and javadoc plugins to an application pom.xml which is built in Intellij, in order to deploy the sources and javadocs to nexus along with the jar files. But the Javadoc plugin would not run, gave this error
Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.2.0:jar (attach-javadocs) on project ced-spark-spring-components: MavenReportException: Error while generating Javadoc: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set.
I am unable to have JAVA_HOME set on my laptop ( unexplained company policy ) , so I concentrated on getting it set in intellij and maven. After a lot of mucking around I got it to work by adding in pom.xml adding
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
to the configuration of the plugin and by setting up this property
<java.home>c:/Program Files/Java/jdk1.8.0_181</java.home>
This worked but no pleasing, eventually stumbled across the intellij maven jdk setting
File | Settings | Build, Execution, Deployment | Build Tools | Maven | Runner
which was defaulting to the internal intellij jdk and which doesn't have javadoc. I changed it to use a full jdk with javadoc external to intellij.
The javadoc plugin then failed the build because of javadoc errors which I was able to configure off by add doclint:none to the plugin congig in pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<additionalOptions>-Xdoclint:none</additionalOptions>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
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>
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
I want to setup Intellij to automatically do what I am doing from the command-line with maven repeatedly, which is to run mvn package -DskipTests to rebuild my jar and run the Appassembler Maven plugin to produce my runnable scripts. Ideally, all I want it to do is hot update the classes within the jar which I have changed.
I have figured out how to tell Intellij to create jars with the Artifact tab in Project Structure, but can I get Intellij to import this artifact information from the pom instead of me setting it up manually?
It does auto-import pom changes, but never imported this artifact info.
This would enable it to use the exact output name of what maven produces, so that whether I'm working from the command-line or IDE I can work with one set of outputs. (reason below)
Appassembler adds an additional step, which includes it copying all the dependencies into its target folder and producing the scripts. If Intellij can't trigger Appassembler, I was thinking maybe Appassembler could use symlinks instead and the when the jar as updated, my runnable app scripts would immediately be using that version. Or in the worse case, I only need to run this particular step from the command-line, the jar having already been built.
Update
In case it helps, here's how I use Appassembler in my pom.xml:
<build>
<plugins>
<plugin>
<executions>
<execution>
<id>package</id>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<programs>
<program>
<mainClass>com.foo.bar.Foobnobicator</mainClass>
<name>gofoo</name>
</program>
</programs>
</configuration>
</plugin>
</plugins>
</build>
Thanks for the advice on the best way to achieve this.
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.