How can I add setup goal to clover in Jenkins? - java

I have a maven project, and I can run coverage on it on my own machine, no problem after following instructions here: https://confluence.atlassian.com/clover/clover-for-maven-2-and-3-quick-start-guide-160399608.html
When I use Jenkins to run clean clover:setup test clover:aggregate clover:clover, it complains that it Could not find goal 'setup' in plugin org.apache.maven.plugins:maven-clover-plugin:2.4 among available goals aggregate, check, instrumentInternal, instrument, log, clover, save-history
Obviously there is no settings file on the Jenkins box. I'm not sure how it even knows those available goals offhand. And I'm not sure how to add that last goal.
I tried this to no avail:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-jira-plugin</artifactId>
<version>5.0.18</version>
</plugin>
</plugins>
</pluginManagement>
The second plugin is what I added, in the hopes to mirror what the settings.xml file was doing on my local machine.
I figure another option is to edit the settings file on Jenkins itself. That is probably the best one...
My Jenkins is in Docker so I just ran docker exec -it abc /bin/bash and got in. When I go to .m2 I don't see a settings.xml. So not sure what Jenkins is saying it's going to reference. I'm going to try out just putting settings.xml here and see how that goes

I made sure that it was using my global settings file, and made that file match what was on my machine. Didn't need to touch my pom.xml at all.

Related

Dynamically package JAR to specific directory for any given Java project using Maven and IntelliJ IDEA

I'm making Minecraft server (Spigot) plugins using IntelliJ IDEA and Maven. I want a button which works on all my Spigot projects (not necessarily automatically determining these projects, though that would also be useful) which packages my plugin directly to my testing server's 'plugins' folder then starts the server.
There are two methods I've thought of to accomplish this, but neither of them work due to limitations with IntelliJ and Maven.
My first idea was to write a batch file which takes the path to the packaged JAR as a parameter, copies the JAR from that path to the 'plugins' folder then starts the testing server.
move "%*" "C:\path\to\my\spigotTestingServer\plugins"
call "C:\path\to\my\spigotTestingServer\startServer.bat"
Then, in the 'Script parameters' for my run configuration, I would reference Maven properties (${project.build.directory}\${project.artifactId}-${project.version}) to obtain this path. However, IntelliJ doesn't seem to allow you to reference Maven properties in any run configuration settings.
My second idea was to modify the package directory directly inside my POM using Maven plugins. However, this means I'd still have to copy this code between projects and it would pollute my Git commits with a path only effective with my filesystem.
Now, I found out Maven has 'build profiles' which could potentially be a solution to this, so I wrote this 'settings.xml'
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>spigotTestingServer</id>
<build>
<finalName>${project.name}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>C:/path/to/my/spigotTestingServer/plugins/</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</settings>
I could then use this for all my Spigot projects by adding '-P spigotTestingServer' to the run configuration.
However, Maven doesn't allow profiles defined in settings.xml to include anything under 'build' including build plugins, which is exactly what I need to modify the package directory.
So, at this point, I'm stuck. Is there any way to get around the issues I've faced so far or are there any alternative solutions to packaging my JAR directly to my Spigot testing server's 'plugins' folder?

Running a jersey project from command line

I have created a RESTful API using jersey that serves some GET endpoints. The thing though is that now I have to ship this project as github link and provide instructions to open and run the project from the command line. I completely build the project using Eclipse and have scoured the web for resources but have no clue as to how to get this done. Could someone care to download the project into their machines and help with instructions to run it from the command line. The README has the links to the public endpoints.
Without needing to actually deploy it your Tomcat instance, you can use the tomcat maven plugin (which is meant for development). It starts an embedded tomcat instance, so you can test your webapps. Just add the following to your pom.xml file
<build>
<finalName>SimpleRestApi</finalName>
<plugins>
...
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
Then from the command line you can just run
mvn tomcat7:run
And a server instance will start. You can then access
http://localhost:8080/api/courses
If you want to change the context path, just use <path>/SimpleRestApi</path>. Then you can access
http://localhost:8080/SimpleRestApi/api/courses

Automatically install a project in the local repository?

I'm trying to work around a maven bug MDEP-187 ( https://issues.apache.org/jira/browse/MDEP-187 ) by not using workspace resolution.
This forces me to do a mvn install for all my dependencies, I'm doing this by creating a launch configuration in eclipse with goal install.
The problem is that i have to create a launch config for every project in my multiproject workspace, in addition to install i have to manually call every launch config and run it. Which just doesn't work.
Is it possible to automatically install a project in the local repository? (whenever i update my code)
If you don't need to run dependency:copy in Eclipse, you can use following work-around:
Add a profile to your pom.xml, something like this:
<profiles>
<profile>
<id>copy</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
[...]
</executions>
</plugin>
</plugins>
<build>
<profile>
</profiles>
Enable workspace resolution in Eclipse.
Then Eclipse will not use dependency:copy, but you can use dependency:copy with command line: mvn install -P copy.
I did go with #khmarbaise solution:
But than you need to can handle the whole thing via
maven-assembly-plugin which can create archives / folders with all the
dependencies. Apart from that a swing ui must be started somehow which
will need some kind of shell script / batch file which you can create
by using appassembler-maven-plugin...And it sounds like you need to go
for a multi module project in maven..cause you might have parts like
core, ui, etc. which are needed to be combined in the end.
#khmarbaise i was in the understanding that the assembly-plugin didn't
support putting dependencies in a lib/ folder (just putting everything
in 1 big jar), but after a little bit of trying i just go myself a zip
with a runnable jar and my dependencies in a lib/ folder. Tomorrow i'm
going to read a bit more about the assembly-plugin. I'm happy ;-

Is it possible consistently pass -Djava.library.path to a maven test from inside a POM file?

I have an external library that needs to be dynamically linked with a test in my java project. The project is setup using maven, and I need to add the following to my vm arguments in eclipse for the test to pass:
-Djava.library.path=${env_var:HOME}/.m2/repository/natives/dist/lib -ea
Unfortunately this means that running the test from maven using: mvn test will always fail.
One work around is to call mvn with a -DargLine argument like so:
mvn test -DargLine="-Djava.library.path=/Users/rob/.m2/repository/natives/dist/lib -ea"
However, clearly this has the problem of being specific to my machine, so I can't put it directly in the pom file. I guess what I'm looking for is a way of modifying that string on a per machine basis kinda like the first line does for eclipse.
I'm also curious how I could put it into the POM file, I've tried placing it inside of <argLine> tags, but that doesn't seems to work, is there something I'm missing:
<argLine>-Djava.library.path=/Users/rob/.m2/repository/natives/dist/lib -ea</argLine>
After some research I've discovered a decent solution to my problem.
In maven your settings.xml file, you can define a location for the localRepository here are the defaults if you set nothing:
Unix/Mac OS X – ~/.m2
Windows – C:\Documents and Settings\username.m2
As you can see this matches at least the first part of the directory I was trying to set: /Users/rob/.m2
Since dynamic linking is OS specific, you may also want to setup a profile for alternate path suffixes. You can do this in a .pom like this:
<profile>
<id>OSX</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<dynamic.libLoc>${settings.localRepository}/natives/dist/lib</dynamic.libLoc>
</properties>
</profile>
You can then use this property in the .pom for the project you wish to test. Under the plugins category you can add:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Djava.library.path=${dynamic.libLoc}</argLine>
</configuration>
</plugin>
Now maven can run those tests without users having to specify the location of the dynamically linked libraries. You can also handle users with different operating systems by just adding another profile.
Note: With regards to my problem with <argLine> earlier. I think I was just using it in the wrong .pom

maven surefire reporting plugin configuration

I have a multi-module maven project. The parent pom.xml is simply a way to reference common information for the 4 subprojects. I have quite a few JUnit tests that run and I also have the Parent Project set up for Project WebSite using the maven-info-reports-plugin.
I have the maven-surefire-report-plugin configured in the parent and it generates the target/site/surefire-report.html file in each of the subprojects with the correct information.
My problem is when I run my project website via site:run I do not see any of the surefire-report.html files in the Project website. The one that shows is in the target directory of the parent and it has no unit tests defined.
Is there a way I can configure maven-surefire-report-plugin or maven-info-reports-plugin to aggregate the subprojects generated surefire reports?
To elaborate on Seph's answer. You can set many of the Maven reports to aggregate results. To do this with the surefire-report plugin you'd do something like this:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<aggregate>true</aggregate>
<!--also set this to link to generated source reports-->
<linkXRef>true</linkXRef>
</configuration>
</plugin>
</plugins>
</reporting>
Note the additional linkXRef property, this allows you to add cross-references to the generated html version of the source produced by the jxr plugin. The jxr plugin can also be set to aggregate, so the two combined allow you to browse your entire project structure.
As far as I know, the maven-info-reports-plugin doesn't do aggregation.
You can add
<aggregate>true</aggregate>
to the surefire plugin in the parent pom.xml.
For command line
mvn surefire-report:report -Daggregate=true
It could be -
mvn clean test -fn surefire-report:report -Daggregate=true
OR
mvn clean install -fn surefire-report:report -Daggregate=true
Note :
fn -> NEVER fail the build, regardless of project result
To add in pom
<aggregate>true</aggregate>

Categories