I'm using the aspectj-maven-plugin together with datanucleus enhancement done by the appengine-maven-plugin.
In case I define the aspectj-maven-plugin before the appengine-maven-plugin everythings seems ok, but when I define the appengine-maven-plugin before the aspectj-maven-plugin then the aspectj-maven-plugin seems to override class enhancements done by the appengine-maven-plugin.
Of course I can just define the aspectj-maven-plugin before the appengine-maven-plugin but I wonder if there are better sophisticated ways to solve this problem?
This is my configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<outxml>true</outxml>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${org.aspectj.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${com.google.appengine.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
You will need to use overweaving in order to get this working. Typically, AspectJ assumes that it is the only bytecode transformer operating on a classfile. So, before it weaves, it will always go back to the original (not transformed class file). When you have something like datanucleus in play, this assumption no longer holds. Overweaving is an option that weaves over an already woven class.
More details here: http://andrewclement.blogspot.ca/2010/05/aspectj-overweaving.html
To enable, use the -Xset:overWeaving=true option to enable it. However, looking at the comments below the blog post, I can see that maven doesn't like the -Xset: options. So, the suggestion is to use a .lst file and add the -X option to that instead.
If this doesn't work, I'd suggest emailing the aspectj-users mailing list.
Related
I've managed to convert my "war" application to a hollow jar.
My biggest issue is that even after following the documentation, still cannot enable debug mode (my desired port is 8784)
I am pretty sure that I am missing something but ... what?
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${wildfly-swarm.version}</version>
<executions>
<execution>
<id>package</id>
<goals>
<goal>package</goal>
</goals>
<configuration>
<hollow>true</hollow>
<properties>
<swarm.debug.port>8784</swarm.debug.port>
<debug.port>8784</debug.port>
<swarm.debug.bootstrap>true</swarm.debug.bootstrap>
<java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>
</properties>
</configuration>
</execution>
</executions>
</plugin>
The swarm.sebug.port property is only relevant when starting the application via the Swarm Maven plugin, or when using the Swarm Arquillian adapter. When starting the application using java -jar myapp-swarm.jar, you need to use the standard Java way of enabling remote debugging, i.e. something like java -Xdebug -agentlib:jdwp=transport=dt_socket,address=8784,server=y,suspend=n -jar myapp-swarm.jar.
You may want to look into:
https://issues.jboss.org/browse/THORN-1321
or
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206848015-Breakpoints-not-working-when-debugging-simple-Java-EE-app-on-wildfly?page=1#community_comment_360000176459
The first link is the relevant one. I am including the second one just for further information if you are using IntelliJ for IDE.
Briefly, here is my pom configuration:
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${version.wildfly.swarm}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
<configuration>
<debugPort>5005</debugPort>
<properties>
<swarm.debug.port>5005</swarm.debug.port>
</properties>
</configuration>
</plugin>
After starting the application with the mvn swarm plugin, I am connecting with a remote debugger.
Good luck!
Edit (2019.05.31):
My current setup for debugging in the pom.xml is the following:
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${version.wildfly.swarm}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmArguments>
<jvmArgument>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArgument>
</jvmArguments>
</configuration>
</plugin>
folks!
I've tried to use the pitest-maven plugin in my Maven / Java project and it is apparently failing to generate an aggregated report (taking into consideration that I have a multi-module project).
I gather some information from the official website and from several other sources, however, none of them was really helpful to define the proper configuration for this scenario.
In a nutshell, my structure looks like:
Parent-Project
Child A
Child B
Child ...
Child N
In some of the submodules, it does make sense to have a pi-test being executed, others not. So to say, my configuration in general is.
Parent-module pom:
<profile>
<id>run-pitest</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.3.2</version>
<configuration>
<outputFormats>
<param>HTML</param>
<param>XML</param>
</outputFormats>
<!--<historyInputFile>${project.basedir}/pitHistory.txt</historyInputFile>-->
<!--<historyOutputFile>${project.basedir}/pitHistory.txt</historyOutputFile>-->
<mutators>
<mutator>CONDITIONALS_BOUNDARY</mutator>
<mutator>MATH</mutator>
<mutator>INCREMENTS</mutator>
<mutator>NEGATE_CONDITIONALS</mutator>
</mutators>
<verbose>true</verbose>
<exportLineCoverage>true</exportLineCoverage>
<testPlugin>testng</testPlugin>
<!--<reportsDirectory>${project.build.directory}/pit-reports</reportsDirectory>-->
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>mutationCoverage</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>site</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
</plugin>
</plugins>
</build>
</profile>
Child project that has mutations:
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<configuration>
<mutationThreshold>80</mutationThreshold>
<exportLineCoverage>true</exportLineCoverage>
</configuration>
</plugin>
</plugins>
And, finally, when I try to execute the phase site (as defined in the parent) even after I executed a clean install that created the files such as linecoverage.xml and mutations.xml, I'm getting this error:
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.820 s
[INFO] Finished at: 2018-04-06T13:20:47+02:00
[INFO] Final Memory: 35M/514M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.pitest:pitest-maven:1.3.2:report-aggregate (report) on project my-parent: An error has occurred in PIT Test Report report generation. Failed to build: no lineCoverageFiles have been set -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
...
Does any of you have a clue if I did a bad configuration or if there is a better way to do any part of this setup?
It seems that you are running into several problems at once :
When running report-aggregate the plugin analyze the dependencies of the module it
runs in and expect everyone of them to have linecoverage.xml and a mutations.xml file. You have to have a submodule dedicated to report aggregation, and you should run report-aggregate only in this submodule.
report-aggregate can't deal with timestamped reports, it must be disabled
I couldn't make it work with the site phase. Not sure if it's a bug in the plugin or if I missed something (keeping the default phase works, but you need to get the report somehow, it won't be in the site).
Putting it all together :
in parent-module pom:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.3.2</version>
<configuration>
<outputFormats>
<param>HTML</param>
<param>XML</param>
</outputFormats>
<!-- omitting mutators, testPlugin and verbose for brevity -->
<exportLineCoverage>true</exportLineCoverage>
<!--
it's currently not possible to aggregate timestamped
reports, so it must be disabled.
-->
<timestampedReports>false</timestampedReports>
</configuration>
<executions>
<execution>
<!--
Use an id to disable it in some submodules
-->
<id>pitest-mutation-coverage</id>
<phase>test</phase>
<goals>
<goal>mutationCoverage</goal>
</goals>
</execution>
<!--
NO report-aggregate here. Most of the time you don't
want it to run.
-->
</executions>
</plugin>
</plugins>
</pluginManagement>
<!-- NO pitest here since its use will vary per submodule -->
</build>
in submodule with mutation :
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<!--
You can put configuration here, but IMOHO it's better to have it
in the parent pom. (so I leave it out here)
-->
</plugin>
</plugins>
in the submodule generating the report :
<!--
Only include submodules where `mutationCoverage` is run.
-->
<dependencies>
<dependency>
<groupId>you.groupId</groupId>
<artifactId>submodule-A</artifactId>
</dependency>
<dependency>
<groupId>you.groupId</groupId>
<artifactId>submodule-B</artifactId>
</dependency>
</dependencies>
and also
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<executions>
<!--
Using the execution id to change its phase to none disables
mutationCoverage in this module.
(not sure it's the best way to do it, but as long as it doesn't
run you should be fine)
-->
<execution>
<id>pitest-mutation-coverage</id>
<phase>none</phase>
</execution>
<execution>
<id>report</id>
<!--
Keep default phase here.
-->
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
I intended to use the Openllet reasoner, as suppose to the other available reasoners. But this reasoner is compatible only with the OWL API 5.X.X distribution. I have a xxx.owl file which contains SWRL rules. Since the existing SWRL API is not compatible with OWL API 5, Ignazio Palmisano had kindly put up a forked repository with required changes, so that it is compatible with the OWL API 5.X.X distribution. Consequently, I removed the dependencies related to SWRL API and drools engine. Instead, I built them locally by downloading the 'zip' files.
Now, with ".jar" files of the SWRL API and Drools loaded into the project in intelliJ, I am presented with this following error:
Exception in thread "main" org.swrlapi.exceptions.SWRLRuleEngineException: Error creating rule engine Drools. Exception: java.lang.NoClassDefFoundError. Message: org/drools/runtime/rule/AgendaFilter
at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:71)
at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:41)
at org.swrlapi.factory.SWRLAPIFactory.createSWRLRuleEngine(SWRLAPIFactory.java:38)
at SWRLrules.main(SWRLrules.java:61)
Caused by: java.lang.NoClassDefFoundError: org/drools/runtime/rule/AgendaFilter
at org.swrlapi.drools.core.DroolsSWRLRuleEngineCreator.create(DroolsSWRLRuleEngineCreator.java:27)
at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:59)
... 3 more
Caused by: java.lang.ClassNotFoundException: org.drools.runtime.rule.AgendaFilter
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more code here
Here I am also attaching the dependencies in pom.xml file:
<dependencies>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-osgidistribution</artifactId>
<version>5.1.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>com.github.galigator.openllet</groupId>
<artifactId>openllet-owlapi</artifactId>
<version>2.6.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.swrlapi.example.SWRLAPIExample</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.swrlapi.example.SWRLAPIExample</mainClass>
</configuration>
</plugin>
</plugins>
</build>
P.S: I built the swrl api and drools engine locally and imported the jar file into the project.
You do not need to remove the dependencies from the pom file (the error you're seeing is caused by some jar having been missed in the manual process).
If you use my swrlapi fork and change the version to, say, 2.0.6-SNAPSHOT, then running locally
mvn clean install
will put a 2.0.6-SNAPSHOT jar in your local maven repository. At that point, change your pom to require swrlapi 2.0.6-SNAPSHOT and you'll get the updated version in your application.
For some reason my client needs my artifacts without version in their names (MyArtifact.jar instead of MyArtifact-1.23.345.jar)
Therefor I added this configuration to my parent pom:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<finalName>${project.artifactId}</finalName>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
This works as expected, meaning that I get jars of the child projects without versions generated in target folder.
However.
One of my jars is an executable jar which depends on the others. Currently I have the maven-jar-plugin configured for that subproject:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>build-classpath</goal>
</goals>
</execution>
</executions>
<configuration>
<fileSeparator>/</fileSeparator>
<pathSeparator>;</pathSeparator>
<outputProperty>bundle.classPath</outputProperty>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<index>true</index>
<manifestEntries>
<Class-Path>${bundle.classPath}</Class-Path>
</manifestEntries>
</archive>
<finalName>${project.artifactId}</finalName>
</configuration>
</plugin>
</plugins>
</build>
The problem is that this generated classpath contains absolute paths to the artifacts on my PC.
Therefore I added the <prefix> tag to the configuration:
<configuration>
<prefix>lib</prefix>
<fileSeparator>/</fileSeparator>
<pathSeparator>;</pathSeparator>
<outputProperty>bundle.classPath</outputProperty>
</configuration>
But then the generated classpath includes the version numbers of the jars.
How can I omit the version numbers and the absolute paths in the classpath?
Problem is: I only want to remove Version numbers from my own artifacts, not from third party libs.
To remove the version from copied dependencies, you can use the stripVersion option of the maven-dependency-plugin.
In the aggregator pom use the dependency:copy-dependencies to copy your jars to some intermediate location.
For you internal dependencies use <stripVersion>true</stripVersion>.
For you 3rd party libraries use <stripVersion>false</stripVersion>.
You may in-/exclude artifacts based on the group id.
For more detail you may look here.
EDIT:
This is to explain how the finalname works.
finalName: This is the name of the bundled project when it is finally built
(sans the file extension, for example: my-project-1.0.jar). It defaults to
${artifactId}-${version}. The term "finalName" is kind of a misnomer,
however, as plugins that build the bundled project have every right to
ignore/modify this name (but they usually do NOT). For example, if the
maven-jar-plugin is configured to give a jar a classifier of test, then the
actual jar defined above will be built as my-project-1.0-test.jar.
Basically it includes almost always the version in your .jar.
In the version (2.6 >), in the <configuration> it allows you to specify the <fileNameMapping>no-version</fileNameMapping>.
The jar plugin alone is able to compute and write the manifest classpath.
This produces a working jar with the desired name
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
I am amazed that what should have been a very easy job is turning into a very annoying task for me. All i need is to pass few command line parameters to my maven exec:exec plugin. unfortunately hours of googling has not helped at all.
Here is my plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>-javaagent:${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar</argument>
<argument>-Xmx256m</argument>
<argument>com.myPackage.Myclass</argument>
</arguments>
</configuration>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
Now from the command prompt i am typing in:
mvn exec:exec -Dexec.args=-Dmy.property=myProperty
I also tried:
mvn exec:exec -Dexec.arguments=-Dmy.property=myProperty
And many other things. However nothing seems to be working. I know that exec:exec runs in a separate VM but as per the documentation -Dexec.args should work for me. Can someone please suggest where i am going wrong?
Two ways to pass command line arguments into mvn:exec:
Method 1, on the command line:
mvn exec:java -Dexec.mainClass="com.myPackage.myClass" -Dexec.args="command line arguments"
Method 2, in the maven POM file:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>com.myPackage.myClass</mainClass>
<commandlineArgs>command line arguments</commandlineArgs>
</configuration>
</plugin>
</plugins>
</build>
Then on the command line all you have to do is run:
mvn exec:java
Good luck.
I was able to get JVM args working for exec:exec using the following after reading this article:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Dhttp.proxyHost=myproxy.example.com</argument>
<argument>-Dhttp.proxyPort=8080</argument>
<argument>-classpath</argument>
<classpath />
<argument>com.example.Main</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
why not use system property?
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>bobo.Abc</mainClass>
<arguments>
<argument>argument1</argument>
</arguments>
<systemProperties>
<systemProperty>
<key>jvmProperty1</key>
<value>dev</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
If you want to pass command line arguments to Java VM use <commandlineArgs> tag instead of <arguments>. Maven Exec Plugin
Cheers
I use the following command line setting to pass arguements to my Main-Class with the exceution plugin.
mvn clean install -Dexec.arguments="arg0"
I don't think the selected answer solves the problem. Here is my somewhat hacky solution that works:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>-Xmx256m</argument>
<argument>com.myPackage.Myclass</argument>
<argument>${myProperty1}</argument> <!-- variable args here!!! -->
<argument>${myProperty2}</argument>
</arguments>
</configuration>
<executions>
<execution>
<id>myExecution</id> <!-- defined an id here! -->
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
Now you can simply execute passing the arguments.
mvn exec:exec#myExecution -DmyProperty1=XXX -DmyProperty2=YYY
The problem is that you use -Dexec.args on the command line and it overrides the <arguments> given in pom.xml. You can use either of them, not both.