intellij maven javadoc plugin JAVA_HOME not set error - maven

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>

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.

wildfly-maven-plugin --> No plugin found for prefix 'wildfly'

When I use wildfly-maven-plugin I get a strange behaviour. I think it is my mistake but I can not figure out what the problem is.
I defined a goal under the wildfly-maven-plugin so when I use maven install then everything is fine and the ear is going to deploy. I did not want to deploy the ear automatically so I removed the executions section and I used the mvn wildfly:deploy but I got an error. If I do not remove this section than the impact is same.
[ERROR] No plugin found for prefix 'wildfly' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo]
pom.xml
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.2.Final</version>
<configuration>
<filename>${project.name}-${parent.artifactId}-${version}.ear</filename>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>redeploy</goal>
</goals>
</execution>
</executions>
</plugin>
The -X command does not provides any useful info.
Use the FQN (Fully Qualified Name) of the maven goal.
mvn org.wildfly.plugins:wildfly-maven-plugin:deploy
Should very explicitly start the wildfly deploy goal and use the configuration you have specified.
The goal shortcuts only works in your configured pluginGroups in settings.xml, and as you can see it only checks 2 groups [org.apache.maven.plugins, org.codehaus.mojo]

Deploying maven project to nexus server using git-describe plugin output

I have several maven projects that deploy to a nexus server. I don't like managing their versions via the pom file, and already use git tags for versioning via git-describe.
I added the git-describe maven plugin with the following config:
<plugin>
<groupId>com.lukegb.mojo</groupId>
<artifactId>gitdescribe-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<goals>
<goal>gitdescribe</goal>
</goals>
<id>git-describe</id>
<phase>initialize</phase>
<configuration>
<outputPrefix></outputPrefix>
</configuration>
</execution>
</executions>
</plugin>
and it works perfectly for mvn package runs - but when I use mvn deploy I end up seeing:
nexus/content/repositories/releases/me/botsko/project/${describe}/project-${describe}.jar
I tried to talk to the plugin author but it's been a few days and no reply.
How can I modify the plugin, or my configuration to property set the version during the deploy phase?
There may be a way to edit the plugin but I'm not familiar with how the maven plugin architecture works.
I solved the problem by writing a shell script that passes the same git-describe value to the maven deploy process:
#!/bin/sh
gitvers=`git describe`
mvn deploy -Ddescribe=$gitvers-SNAPSHOT
Just make sure you use <version>${describe}</version> or similar in the POM.

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.

Configure jacoco agent for sonar2.12 (Multi Module maven)

The Sonar latest version 2.12 has the Jacoco plugin integrated and i want to use it for my code coverage part on a multi module project.
I have a structure like this
proj.com.parent
proj.com.provider
proj,com.test
The Test cases for the provider project are in the test project. When i set the Code coverage plugin in sonar as jacoco it executes fine , but the combined code covergae is not presented on the DashBoard. Ihave seen a post that a single jacoco.exec file can solve the problem , but i am unable to do so.
I have tried to configure the below in my pom as below
<profile>
<id>sonar</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-javaagent:${sonar.jacoco.jar}=destfile=${sonar.jacoco.reportPath}</argLine>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<sonar.jacoco.reportPath>${basedir}/code-coverage/jacoco.exec</sonar.jacoco.reportPath>
<sonar.jacoco.jar> C:\sonar-2.12\war\sonar-server\deploy\plugins\jacoco\META-INF\lib\org.jacoco.agent-0.5.3.201107060350.jar</sonar.jacoco.jar>
</properties>
But on maven commandline " mvn clean install " i get this error :
Failed to find Premain-Class manifest attribute in C:\sonar-2.12\war\sonar-server\deploy\plugins\jacoco\META-INF\lib\org.jacoco.agent-0.5.3.201107060350.jar
Error occurred during initialization of VM
agent library failed to init: instrument
Can anyone provide any help on this ?
the jar you are pointing to is not the jar..extract that using winrar and you will get another jar inside it. called jacocoagent.jar .to check whether you got the right jar just extract jacocoagent.jar
and look for manifest.mf and it should have an entry for premain class.
that should do.
I had the same problem. Take a look at the Jacoco agent artifacts at the central repository.
There is a normal jar artifact, and there is a jar with classifier runtime. You need the "runtime" artifact to be used as agent jar. What I do, I simply download the Jacoco agent runtime jar with maven dependency plugin like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>download-jacoco-agent</id>
<phase>pre-integration-test</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>0.6.3.201306030806</version>
<classifier>runtime</classifier>
<outputDirectory>${project.build.directory}</outputDirectory>
<destFileName>jacoco-agent.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Then you just need to define the following command line option:
<argLine>-javaagent:${project.build.directory}/jacoco-agent.jar=destfile=${sonar.jacoco.reportPath}</argLine>
Perhaps you should try setting the property sonar.core.codeCoveragePlugin to the value jacoco. The default code coverage tool in Sonar is still cobertura. See the following doco on code coverage.
If that doesn't help, I found the following link (which runs Jacoco from Maven as your trying to do):
Separating Code Coverage With Maven, Sonar and Jacoco

Resources