I am using AspectJ (not Spring) to implement AOP in my Java Web application. It works fine when built by Maven project in Eclipse.
But putting and deploying the war package on the remote server, the AOP won't execute.
here's part of pom.xml:
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.9</version>
<!--<properties>
<war.bundle>true</war.bundle>
</properties>
-->
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.9</version>
<!--<properties>
<war.bundle>true</war.bundle>
</properties>
-->
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.8</version>
<!--<properties>
<war.bundle>true</war.bundle>
</properties>
-->
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<privateScope>true</privateScope>
<showWeaveInfo>true</showWeaveInfo>
<source>1.7</source>
<target>1.7</target>
<complianceLevel>1.7</complianceLevel>
<!-- <encoding>UTF-8</encoding> -->
<verbose>false</verbose>
<outxml>true</outxml>
<aspectLibraries>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}/src/main/webapp/WEB-INF/lib</directory>
</fileset>
<fileset>
<directory>${project.basedir}/../deploy</directory>
<includes>
<include>${project.artifactId}.war</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-installed</id>
<phase>install</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>${project.packaging}</type>
<destFileName>rm-cloud-web.war</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.basedir}/../deploy</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
<execution>
<id>unpack-dependencies</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/test-classes</outputDirectory>
<overWriteReleases>true</overWriteReleases>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any advice?
Sorry guys, AspectJ did work on the server side and it does NOT need to add any extra jar file. I tried to log some info in an aspect method by using a enum that been advised, means the advise will be called recursively that caused stackoverflowexception.
Now I cant exclude Enum whthin the curtain class:
LogLevel is a enum in the class: xxx.xx.Utility
The compile info:
[INFO] Join point 'method-execution(int[] xxx.xx.Utility.$SWITCH_TABLE$xxx$xx$Utility$LogLevel())' in Type 'xxx.xx.Utility' (Utility.java:49) advised by before advice from 'zzz.zz.AAAA' (AAAA.aj:5)
my aspect content:
pointcut pc() : (execution(* xxx.xx..(..)) && !within(is(EnumType)));
before() : pc() {
...
}
Related
I am trying to reference a Java class from a Kotlin file, but the problem is that I cannot reference the package containing the Java sources.
What I am trying:
fun main.dmla.java.parser.DMLAParser.parseDmla(source: Source): Any {
val lexer = DMLALexer(CharStreams.fromString(source.characters.toString()))
val parser = DMLAParser(CommonTokenStream(lexer))
val walker = DmlaWalker()
return walker.visit(parser.model())
}
I cannot reference the main.dmla.java package for some reason, therefore I cannot reach the DMLAParser class.
The Maven pom.xml looks like this:
<parent>
<groupId>DMLAGraalVM</groupId>
<artifactId>DMLA-parent</artifactId>
<version>0.0.1</version>
</parent>
<artifactId>language</artifactId>
<properties>
<java.version>1.8</java.version>
<kotlin.version>1.3.21</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-api</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-dsl-processor</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-tck</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/dmla/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/dmla/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>dmla</finalName>
<artifactSet>
<excludes>
<exclude>org.graalvm.truffle:truffle-api</exclude>
<exclude>org.graalvm.truffle:truffle-dsl-processor</exclude>
<exclude>org.graalvm.truffle:truffle-tck</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
What am I doing wrong?
I have added a custom PMD rule using official documentation (http://pmd.sourceforge.net/pmd-5.1.0/howtowritearule.html)
Rule:
package com.comp.www.lty.awards.service.pmd;
import net.sourceforge.pmd.lang.ast.*;
import net.sourceforge.pmd.lang.java.ast.*;
import net.sourceforge.pmd.lang.java.rule.*;
public class WhileLoopsMustUseBracesRule extends AbstractJavaRule {
public Object visit(ASTWhileStatement node, Object data) {
Node firstStmt = node.jjtGetChild(1);
if (!hasBlockAsFirstChild(firstStmt)) {
addViolation(data, node);
}
return super.visit(node,data);
}
private boolean hasBlockAsFirstChild(Node node) {
return (node.jjtGetNumChildren() != 0 && (node.jjtGetChild(0) instanceof ASTBlock));
}
}
This is my ruleset xml file:
<?xml version="1.0"?>
<ruleset name="My custom rules"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>While loop desc</description>
<rule name="WhileLoopsMustUseBracesRule"
message="Avoid using 'while' statements without curly braces"
class="com.comp.www.lty.awards.service.pmd.WhileLoopsMustUseBracesRule">
<description>
Avoid using 'while' statements without using curly braces
</description>
<priority>3</priority>
<example>
<![CDATA[
public void doSomething() {
while (true)
x++;
}
]]>
</example>
</rule>
</ruleset>
I am using mvn to run these pmd rules. Works fine when I try to use existing rules from pmd jar, but whenever I try to use my above custom rule, I am getting ClassNotFoundException.
Stacktrace:
java.lang.ClassNotFoundException: com.comp.www.lty.awards.service.pmd.WhileLoopsMustUseBracesRule
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
at net.sourceforge.pmd.RuleSetFactory.parseSingleRuleNode(RuleSetFactory.java:377)
at net.sourceforge.pmd.RuleSetFactory.parseRuleNode(RuleSetFactory.java:291)
at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.java:242)
at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:176)
at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:171)
at net.sourceforge.pmd.RuleSetFactory.parseRuleSetReferenceNode(RuleSetFactory.java:331)
at net.sourceforge.pmd.RuleSetFactory.parseRuleNode(RuleSetFactory.java:289)
at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.java:242)
at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:176)
at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:171)
at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java:135)
at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java:119)
at net.sourceforge.pmd.RulesetsFactoryUtils.getRuleSets(RulesetsFactoryUtils.java:31)
at net.sourceforge.pmd.processor.AbstractPMDProcessor.createRuleSets(AbstractPMDProcessor.java:54)
at net.sourceforge.pmd.processor.MultiThreadProcessor.processFiles(MultiThreadProcessor.java:38)
at net.sourceforge.pmd.PMD.processFiles(PMD.java:352)
at org.apache.maven.plugin.pmd.PmdReport.executePmd(PmdReport.java:377)
at org.apache.maven.plugin.pmd.PmdReport.executePmdWithClassloader(PmdReport.java:280)
at org.apache.maven.plugin.pmd.PmdReport.canGenerateReport(PmdReport.java:254)
at org.apache.maven.reporting.AbstractMavenReport.execute(AbstractMavenReport.java:119)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.executeForkedExecutions(MojoExecutor.java:365)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:199)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Although not an ideal solution, but even I spent time to include this custom rule class file in the pmd jar (Custom Java PMD rule: Can't find the class CustomRule), but that didn't help either.
pom.xml:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring-boot-starter-parent
1.4.0.RELEASE
lty-awards-service
com.comp.www
war
lty-awards-service
Spring Boot Service Sample
1.0-SNAPSHOT
http://maven.apache.org
1.8
<findbugs-maven-plugin.version>3.0.3</findbugs-maven-plugin.version>
<findbugs.include.filter.location>buildtools/findbugs/include.xml</findbugs.include.filter.location>
<findbugs.exclude.filter.location>buildtools/findbugs/exclude.xml</findbugs.exclude.filter.location>
<maven-pmd-plugin.version>3.5</maven-pmd-plugin.version>
<pmd.version>5.3.2</pmd.version>
<pmdRule.version>5.1.0</pmdRule.version>
<pmd.ruleset.location>buildtools/pmd-rules/ltyawardsservicepmd.xml</pmd.ruleset.location>
<pmd.skip>false</pmd.skip>
<pmd.typeResolution>true</pmd.typeResolution>
<!-- spring boot -->
<debug.port>5000</debug.port>
<run.jvmArguments>-Dspring.profiles.active=dev -Dapplication.home=. -Dapplication.name=${project.name}
-Dapplication.environment=dev -Dproject.name=${project.name} -Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${debug.port}
</run.jvmArguments>
<error-inspector.version>0.1.9</error-inspector.version>
<platform-diagnostics.version>0.0.43</platform-diagnostics.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>${pmdRule.version}</version>
<scope>system</scope>
<systemPath>/Users/babu/.m2/repository/net/sourceforge/pmd/pmd/5.1.0/test.jar</systemPath>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.comp.prime.errorcatalog</groupId>
<artifactId>error-inspector</artifactId>
<version>${error-inspector.version}</version>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/error-inspect</outputDirectory>
<destFileName>inspect.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.comp.www.platform</groupId>
<artifactId>platform-diagnostics-main</artifactId>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/error-inspect/lib</outputDirectory>
<destFileName>platform-diagnostics-main.jar</destFileName>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<message>.*** ERROR: Detected Maven version ${maven.version}, We need Maven 3.0.3 or
higher ***.
</message>
<version>[3.0.3,)</version>
</requireMavenVersion>
<requireJavaVersion>
<message>.*** ERROR: Detected JDK version ${java.version}, We need JDK
${project.jdk.version} or higher ***.
</message>
<version>${project.jdk.version}</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
<execution>
<id>enforce-dont-exist</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireFilesDontExist>
<files>
<file>${project.basedir}/src/main/scala</file>
</files>
</requireFilesDontExist>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${project.jdk.version}</source>
<target>${project.jdk.version}</target>
<encoding>UTF-8</encoding>
</configuration>
<version>3.3</version>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>${scala-maven-plugin.version}</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaCompatVersion>${scala.major.minor.version}</scalaCompatVersion>
<jvmArgs>
<jvmArg>-Xms512m</jvmArg>
<jvmArg>-Xmx2048m</jvmArg>
</jvmArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${maven-pmd-plugin.version}</version>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>${pmd.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>${pmd.version}</version>
</dependency>
<dependency>
<groupId>WhileLoopsMustUseBracesRule</groupId>
<artifactId>pmd.ruleset</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>/Users/babu/Downloads/cache.jar</systemPath>
</dependency>
<dependency>
<groupId>com.comp.www.platform</groupId>
<artifactId>platform-build-tools</artifactId>
<version>${platform-build-tools.version}</version>
</dependency>
</dependencies>
<configuration>
<targetJdk>${project.jdk.version}</targetJdk>
<includeTests>true</includeTests>
<skip>${pmd.skip}</skip>
<sourceEncoding>${project.sourceEncoding}</sourceEncoding>
<rulesets>
<ruleset>${pmd.ruleset.location}</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<id>cpd-report</id>
<phase>test-compile</phase>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
<goal>pmd</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!--<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</reporting>-->
Here test.jar is my jar bundled (i.e. pmd jar unbundled, added class file & ruleset and again bundled it as test.jar). Although this is not how I want to use the rule. But if there is a better way to use pmd jar as it is & add a mvn dependency for new rule that is the ideal solution I'm looking for. Thanks!
You need to add your custom rule jar to the classpath when PMD runs. You should bundle your custom PMD rule in its own Maven dependency, then you can include it in the PMD plugin classpath by adding a dependency to your plugin configuration like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.7</version>
<dependencies>
<dependency>
<groupId>com.foo.bar</groupId>
<artifactId>my-custom-pmd-rule</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
...
</plugin>
See this page for more information about plugin classloading. See how it says:
Please note that the plugin classloader does neither contain the dependencies of the current project nor its build output
Try changing your pom.xml file to the following. Notice I moved your test.jar dependency to the plugin dependencies so that it'll be loaded on the plugin's classpath. Note that you don't have to bundle your rules with PMD. You just need to package your rules in its own jar and include it in the plugin dependencies section.
<findbugs-maven-plugin.version>3.0.3</findbugs-maven-plugin.version>
<findbugs.include.filter.location>buildtools/findbugs/include.xml</findbugs.include.filter.location>
<findbugs.exclude.filter.location>buildtools/findbugs/exclude.xml</findbugs.exclude.filter.location>
<maven-pmd-plugin.version>3.5</maven-pmd-plugin.version>
<pmd.version>5.3.2</pmd.version>
<pmdRule.version>5.1.0</pmdRule.version>
<pmd.ruleset.location>buildtools/pmd-rules/ltyawardsservicepmd.xml</pmd.ruleset.location>
<pmd.skip>false</pmd.skip>
<pmd.typeResolution>true</pmd.typeResolution>
<!-- spring boot -->
<debug.port>5000</debug.port>
<run.jvmArguments>-Dspring.profiles.active=dev -Dapplication.home=. -Dapplication.name=${project.name}
-Dapplication.environment=dev -Dproject.name=${project.name} -Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${debug.port}
</run.jvmArguments>
<error-inspector.version>0.1.9</error-inspector.version>
<platform-diagnostics.version>0.0.43</platform-diagnostics.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.comp.prime.errorcatalog</groupId>
<artifactId>error-inspector</artifactId>
<version>${error-inspector.version}</version>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/error-inspect</outputDirectory>
<destFileName>inspect.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.comp.www.platform</groupId>
<artifactId>platform-diagnostics-main</artifactId>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/error-inspect/lib</outputDirectory>
<destFileName>platform-diagnostics-main.jar</destFileName>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<message>.*** ERROR: Detected Maven version ${maven.version}, We need Maven 3.0.3 or
higher ***.
</message>
<version>[3.0.3,)</version>
</requireMavenVersion>
<requireJavaVersion>
<message>.*** ERROR: Detected JDK version ${java.version}, We need JDK
${project.jdk.version} or higher ***.
</message>
<version>${project.jdk.version}</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
<execution>
<id>enforce-dont-exist</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireFilesDontExist>
<files>
<file>${project.basedir}/src/main/scala</file>
</files>
</requireFilesDontExist>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${project.jdk.version}</source>
<target>${project.jdk.version}</target>
<encoding>UTF-8</encoding>
</configuration>
<version>3.3</version>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>${scala-maven-plugin.version}</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaCompatVersion>${scala.major.minor.version}</scalaCompatVersion>
<jvmArgs>
<jvmArg>-Xms512m</jvmArg>
<jvmArg>-Xmx2048m</jvmArg>
</jvmArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${maven-pmd-plugin.version}</version>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>${pmd.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>${pmd.version}</version>
</dependency>
<dependency>
<groupId>WhileLoopsMustUseBracesRule</groupId>
<artifactId>pmd.ruleset</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope><systemPath>/Users/babu/Downloads/cache.jar</systemPath>
</dependency>
<dependency>
<groupId>com.comp.www.platform</groupId>
<artifactId>platform-build-tools</artifactId>
<version>${platform-build-tools.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>${pmdRule.version}</version>
<scope>system</scope>
<systemPath>/Users/babu/.m2/repository/net/sourceforge/pmd/pmd/5.1.0/test.jar</systemPath>
</dependency>
</dependencies>
<configuration>
<targetJdk>${project.jdk.version}</targetJdk>
<includeTests>true</includeTests>
<skip>${pmd.skip}</skip>
<sourceEncoding>${project.sourceEncoding}</sourceEncoding>
<rulesets>
<ruleset>${pmd.ruleset.location}</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<id>cpd-report</id>
<phase>test-compile</phase>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
<goal>pmd</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!--<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</reporting>-->
I'm trying to use Lombok in combination with AspectJ and Maven.
So, what's the problem?
When I use the AspectJ Maven Plugin (www.mojohaus.org/aspectj-maven-plugin/), it takes the sources and compiles them and ignores changes made by Lombok. I followed this tutorial and came up with this code and AspectJ works, but Lombok dies with this message:
[WARNING] You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
Your processor is: org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchProcessingEnvImpl
Lombok supports: sun/apple javac 1.6, ECJ
So, does anyone know how to get Lombok in combination with AspectJ working?
Use ajc to process classes.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
<configuration>
<complianceLevel>8</complianceLevel>
<source>8</source>
<target>8</target>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
<Xlint>ignore</Xlint>
<encoding>UTF-8</encoding>
<!-- IMPORTANT-->
<excludes>
<exclude>**/*.java</exclude>
</excludes>
<forceAjcCompile>true</forceAjcCompile>
<sources/>
<!-- IMPORTANT-->
<aspectLibraries>
<aspectLibrary>
<groupId>you.own.aspect.libary</groupId>
<artifactId>your-library</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>process-classes</phase>
<goals>
<!-- use this goal to weave all your main classes -->
<goal>compile</goal>
</goals>
<configuration>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
</weaveDirectories>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<phase>process-test-classes</phase>
<goals>
<!-- use this goal to weave all your test classes -->
<goal>test-compile</goal>
</goals>
<configuration>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/test-classes</weaveDirectory>
</weaveDirectories>
</configuration>
</execution>
</executions>
</plugin>
Use delombok to generate normal source code. And then proceed as you would if Lombok were not being used.
Store your Lombok-annotated code in main/src/lombok (for example) and then have the delombok plugin convert these annotations into normal code and into the directory /delomboked (for example).
I tried various solutions, finally specifying the javac compiler option like the below one worked
This works for me with command line mvn clean install, but in Eclipse IDE, the problem is not solved, eg. log is not correctly recognized for #Slf4j.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.10</version>
<configuration>
<verbose>true</verbose>
<showWeaveInfo>true</showWeaveInfo>
<source>1.7</source>
<target>1.7</target>
<complianceLevel>1.7</complianceLevel>
<!-- <encoding>UTF-8</encoding> -->
<verbose>false</verbose>
<Xlint>ignore</Xlint>
<outxml>true</outxml>
<forceAjcCompile>true</forceAjcCompile>
<reweavable>false</reweavable>
<aspectLibraries>
<aspectLibrary>
<groupId>com.aspectj.library.yours</groupId>
<artifactId>your-library</artifactId>
</aspectLibrary>
</aspectLibraries>
<!-- this is important: start-->
<sources/>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
</weaveDirectories>
<!-- this is important: end-->
</configuration>
<executions>
<execution>
<!-- The right phase is very important! Compile and weave aspects after all classes compiled by javac -->
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.9</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.9</version>
</dependency>
</dependencies>
</plugin>
I had a configuration/excludes/exclude section with the spring-boot-maven-plugin where the "aspectjweaver" dependency had been declared. The exclude section had "org.projectlombok" in it, and looks like that's why none of my lombok annotations were being processed while building using "mvn clean install"
I initially had this:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<configuration>
<excludes> <!------- THIS IS WHERE my problem started by exluding lombok -->
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
When I removed the excludes part, then the build started taking the lombok annotations and worked. This is my section now:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
SpringBoot AND Java: 16
At this moment (19-11-2022) aspectJ plugin not support 17
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/>
</parent>
...
YOUR GROUP, ARTIFACT NAME, VERSION ETC HERE
...
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>kkl.lib.dev.tools</groupId>
<artifactId>lib-dev-tools</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.14.0</version>
<configuration>
<showWeaveInfo/>
<sources/>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
</weaveDirectories>
<forceAjcCompile>true</forceAjcCompile>
<source>16</source>
<target>16</target>
<proc>none</proc>
<complianceLevel>16</complianceLevel>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
After reseach and testing all day, here is my success build.
Main idea is using javac to compile code first (compliance with lombok) and after that use aspectj only for weaving class.
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.1</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>unwovenClassesFolder</id>
<phase>generate-resources</phase>
<configuration>
<tasks>
<delete dir="${project.build.directory}/unwoven-classes"/>
<mkdir dir="${project.build.directory}/unwoven-classes"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<!-- Modifying output directory of default compile because non-weaved classes must be stored
in separate folder to not confuse ajc by reweaving already woven classes (which leads to
to ajc error message like "bad weaverState.Kind: -115") -->
<id>default-compile</id>
<configuration>
<source>16</source>
<target>16</target>
<outputDirectory>${project.build.directory}/unwoven-classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.14.0</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
<Xlint>ignore</Xlint>
<encoding>UTF-8</encoding>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/unwoven-classes</weaveDirectory>
</weaveDirectories>
<!-- IMPORTANT-->
<excludes>
<exclude>**/*.java</exclude>
</excludes>
<forceAjcCompile>true</forceAjcCompile>
<sources/>
<!-- IMPORTANT-->
<complianceLevel>16</complianceLevel>
<source>16</source>
<target>16</target>
</configuration>
<executions>
<execution>
<!-- Compile and weave aspects after all classes compiled by javac -->
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<complianceLevel>16</complianceLevel>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
I am trying to use moskito-inspect tool in embedded mode, here is my pom.xml
<properties>
<moskito.version>2.5.5</moskito.version>
<moskito-central.version>1.1.0</moskito-central.version>
</properties>
...
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>net.anotheria</groupId>
<artifactId>moskito-aop</artifactId>
</aspectLibrary>
</aspectLibraries>
<complianceLevel>1.7</complianceLevel>
<source>1.7</source>
<target>1.7</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<artifactItems><artifactItem>
<groupId>net.anotheria</groupId>
<artifactId>moskito-webui</artifactId>
<version>${moskito.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/tmp</outputDirectory>
<includes>moskito/**,**/*.jsp</includes>
</artifactItem></artifactItems>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>unpack</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/tmp</directory>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
...
<dependencies>
<dependency>
<groupId>net.anotheria</groupId>
<artifactId>moskito-core</artifactId>
<version>${moskito.version}</version>
</dependency>
<dependency>
<groupId>net.anotheria</groupId>
<artifactId>moskito-aop</artifactId>
<version>${moskito.version}</version>
</dependency>
<dependency>
<groupId>net.anotheria</groupId>
<artifactId>moskito-web</artifactId>
<version>${moskito.version}</version>
</dependency>
<dependency>
<groupId>net.anotheria</groupId>
<artifactId>moskito-webui</artifactId>
<version>${moskito.version}</version>
</dependency>
<dependency>
<groupId>net.anotheria</groupId>
<artifactId>moskito-inspect-embedded</artifactId>
<version>${moskito.version}</version>
</dependency>
<dependency>
<groupId>net.anotheria</groupId>
<artifactId>moskito-inspect-jersey</artifactId>
<version>${moskito.version}</version>
</dependency>
<dependency>
<groupId>org.moskito</groupId>
<artifactId>moskito-central-embedded-connector</artifactId>
<version>${moskito-central.version}</version>
</dependency>
<dependency>
<groupId>org.moskito</groupId>
<artifactId>moskito-central-storages</artifactId>
<version>${moskito-central.version}</version>
</dependency>
</dependencies>
When I am running maven clean install I am getting war-file, which has the next inner structure:
When I deploy this war-file in tomcat, I can access my application by this URL:
http://localhost:8080/ada
(where ada - application name)
so I have tried to access moskito-inspect webui by this URLs:
http://localhost:8080/ada/moskito
http://localhost:8080/moskito
http://localhost:8080/ada/mui
http://localhost:8080/mui
However, tomcat response for all these links in 404 [Not found].
What am I doing wrong, may be someone faced the same problem?
Thanks in advance
I have figure out that you should add to your web.xml Moskito filters configuration - like in this article.
But author also said in this article that
With version 2.4.0 and servlet spec 3.0 no changes of the web.xml are
needed.
That's why I ignored that guide - very misleading advice!
No matter how much I do mvn clean install even with -U this dependency (along with some other) is not being coped into the target\app-1.0-SNAPSHOT\WEB-INF\lib folder:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
Not sure why this happens now, when in the pom.xml there is the <packaging>war</packaging>
build
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.version}</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- Copies static web files from src/main/webapp to target/${webappDirectory} -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<!-- the exploded goal gets executed during compile phase -->
<phase>compile</phase>
<goals>
<goal>exploded</goal>
<goal>war</goal>
</goals>
</execution>
</executions>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>${project.artifactId}</warName>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>