I'm facing problems to build an aspect project in eclipse with maven. When I run maven through eclipse "Run As > Maven build" I obtain this message: <...>/Clazz.java:[5,32] error: cannot find symbol. So, it looks like aspectj is not weaving the code through maven.
I distilled the problem until have class and an aspect that defines an intertype attribute in the mentioned class, as follows:
public class Clazz {
public static void main(String[] args) {
System.out.println(new Clazz().string);
}
}
public aspect Aspect {
public String Clazz.string = "string";
}
The pom.xml looks like this:
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.3</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The problem appears to be that the maven-compiler-plugin doesn't know to get out of the way when you have an AspectJ compile and throws errors that kill the build before ajc gets a chance to pull in the ITDs. My solution has been to disable maven-compiler-plugin entirely and let ajc handle compiling the .java files:
<!-- disable compiler because compiler chokes on ITDs -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
Actually you do not need to deactivate the Maven Compiler Plugin, but you need to do two things according to what I found out for someone who had a similar problem here:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<aspectj.version>1.8.1</aspectj.version>
</properties>
<!-- (...) -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<!-- IMPORTANT -->
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.7</source>
<target>1.7</target>
<Xlint>ignore</Xlint>
<complianceLevel>1.7</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<!-- IMPORTANT -->
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
I.e. you need to
use incremental compilation in Maven Compiler Plugin 3.1 (attention, the switch is reversed, which is probably a bug) and
assign execution phase "process-sources" to AspectJ Maven Plugin 1.6.
That should do it.
Related
My project POM has following plugins-
<build>
<plugins>
<plugin>
<groupId>org.jasig.mojo.jspc</groupId>
<artifactId>jspc-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<directory>${basedir}/src/main/webapp/</directory>
<includes>
<include>**/*.jsp</include>
</includes>
</sources>
<includeInProject>false</includeInProject>
<validateXml>false</validateXml>
</configuration>
<dependencies>
<dependency>
<groupId>org.jasig.mojo.jspc</groupId>
<artifactId>jspc-compiler-tomcat8</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.5.3</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>utf8</encoding>
</configuration>
</plugin>
</plugins>
</build>
I'm using apache-maven-3.6.3 and Intellij IDE for building my project.
But when executing mvn clean verify, I get the error-
Failed to execute goal
org.jasig.mojo.jspc:jspc-maven-plugin:2.0.2:compile: Failed to compile
JSPS
It is due to in tomcat 7 by default SKIP IDENTIFIER CHECK feature is false.
Hence supply-Dorg.apache.el.parser.SKIP_IDENTIFIER_CHECK=true as an argument while maven clean installing.
Alternatively a work around is also to use org.apache.sling jspc-maven-plugin
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>jspc-maven-plugin</artifactId>
<version>2.2.2</version>
<executions>
<execution>
<id>compile-jsp</id>
<goals>
<goal>jspc</goal>
</goals>
</execution>
</executions>
</plugin>
I am using JaCoCo code coverage, but the report is including classes from jar, lib. (Offline Instrumentation, Maven)
I solved the problem with the offline configuration since "aspectj-maven-plugin" was changing the class files, and also now I successfully exclude the packages outside of target/classes -> src. thanks to this answer in stackoverflow.
But now I am getting the classes from jar, lib inside the report and I have not idea how to exclude then. I Show my configuration and examples below
I also tried this solution Exclude classes of jar files from jacoco coverage report But it doesn't work for me.
<exclude>**/lib/*</exclude>
My jacoco offline configuration:
<properties>
<jacoco.version>0.8.4</jacoco.version>
<argLine></argLine>
</properties>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<version>${jacoco.version}</version>
</dependency>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>instrument</goal>
<goal>restore-instrumented-classes</goal>
<goal>report</goal>
</goals>
<configuration>
<!-- this configuration affects all goals -->
<excludes>
<exclude>*</exclude>
<exclude>com/company/rrPackage/**/*.class</exclude>
<exclude>org/**/*.class</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
surefire-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<testNGArtifactName>...</testNGArtifactName>
<suiteXmlFiles>
<suiteXmlFile>...</suiteXmlFile>
</suiteXmlFiles>
<skip>${skip.test}</skip>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
<properties>
...
</properties>
</configuration>
</plugin>
And the reason what I think that I am getting classes from jar inside de jacoco:report. In my pom.xml I have the following dependencies:
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.9</version>
</dependency>
Also I have a couple of import in my classes like this
import org.hsqldb.lib.StringUtil;
for example:
This has no dependency on the pom.xml but is used in one of the project classes, and jacoco shows it in the report
import javax.mail.internet.AddressException;
I have other cases with the same behavior that result in the same problem: Jacoco show those classes from jar in the report, as shown in the images
Try includes instead of excludes. Notice that you need .class at the end.
try something like that:
<configuration>
<includes>
<include>com/company/package/**/*.class</include>
</includes>
</configuration>
Base on your example:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>instrument</goal>
<goal>restore-instrumented-classes</goal>
<goal>report</goal>
</goals>
<configuration>
<!-- this configuration affects all goals -->
<includes>
<include>com/company/packageToInclude/**/*.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
I don't know how you generate lib directory, because you don't provide complete example.
However in case of the following example
src/main/java/Example.java
class Example {
}
src/test/java/ExampleTest.java
public class ExampleTest {
#org.junit.Test
public void test() {
new Example();
}
}
and pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>0.1-SNAPSHOT</version>
<properties>
<jacoco.version>0.8.4</jacoco.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<version>${jacoco.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>junit</includeArtifactIds>
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>instrument</goal>
<goal>restore-instrumented-classes</goal>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
execution of mvn clean verify produces
$ ls -R target/classes
target/classes:
Example.class lib
target/classes/lib:
junit-4.12.jar
and following report
And after addition of following <configuration>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>instrument</goal>
<goal>restore-instrumented-classes</goal>
<goal>report</goal>
</goals>
<configuration>
<excludes>
<exclude>lib/**</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
execution of the same command mvn clean verify produces following report
If the above doesn't help, then please provide absolutely complete example allowing everybody else to reproduce exactly the same what you do.
I transferred a big java project to maven and replaced all the libraries used with maven and I can run debug or start just fine meaning that it works normally but for some reason whenever I try to run maven test or install or anything that tries to compile it using maven it fails.
This is my pom file (I use nexus for third party jars):
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pbclient2</groupId>
<artifactId>pbclient2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Name</name>
<description>Description</description>
<dependencies>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
.
.
.
<dependency>
<groupId>mxmlc</groupId>
<artifactId>mxmlc</artifactId>
<version>1.0</version>
<classifier>mxmlc</classifier>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src</directory>
</resource>
</resources>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<inherited>true</inherited>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- <plugin> <groupId>com.google.appengine</groupId> <artifactId>appengine-maven-plugin</artifactId>
<version>1.9.32</version> <configuration> <enableJarClasses>false</enableJarClasses>
</configuration> <executions> <execution> <goals> <goal>endpoints_get_discovery_doc</goal>
</goals> </execution> </executions> </plugin> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<phase>test</phase>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build></project>
I have tried a lot of plugins and tried deleting the .m2 repository but nothing seems to help.
All the errors I get are
[ERROR] /C:/Users/worx-pc-01/git/PbClient/pbclient2/src/pb/ui/panels/admin/workorders/configuration/namingConvention/GenericNamingConventionTableModel.java:[10,24] package com.pb.hibernate does not exist
or
[ERROR] /C:/Users/worx-pc-01/git/PbClient/pbclient2/src/pb/ui/panels/admin/workorders/configuration/namingConvention/GenericNamingConventionTableModel.java:[192,36] cannot find symbol
symbol: class PbPwoNamingConfiguration
location: class pb.ui.panels.admin.workorders.configuration.namingConvention.GenericNamingConventionTableModel
The package does exist and I don't understand why this won't work like its supposed to.
Am I doing something wrong since I just started using maven.
The error messages suggest to me that either the package com.pb.hibernate doesn't exist in your project (maybe it has been renamed and your IDE didn't update every use properly) or it exists in an external dependency which your IDE has somehow got in its path when running/debugging, but the dependency isn't defined correctly in your pom, and so running mvn clean install fails
I am writing a mixed Java/Scala project and my Eclipse compiler is giving errors for all of the Scala code. It seems to try to compile it as Java instead of Scala. However, when I run a clean, all of the errors go away. Also, building this using maven works completely fine.
I am building this project in Maven. Originally this project was only Java, so I added the necessary plugins/dependencies into my pom.xml.
Any idea why Eclipse is treating my Scala files as Java?
Here's my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.antlrfun</groupId>
<artifactId>antlrfun</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Antlr4 Spark/Solr</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<antlr4.visitor>true</antlr4.visitor>
<antlr4.listener>true</antlr4.listener>
</properties>
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.5</version>
</dependency>
<dependency>
<groupId>junit</groupId> <!-- NOT org.junit here -->
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.5</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.antlrfun.Hello</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<compilerArguments>
<Xlint/>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.1</version>
<configuration>
<sourceDirectory>src/main/java</sourceDirectory>
<outputDirectory>src/main/generated-sources</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<!-- Run scala compiler in the process-resources phase, so that dependencies on
scala classes can be resolved later in the (Java) compile phase -->
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<!-- Run scala compiler in the process-test-resources phase, so that dependencies on
scala classes can be resolved later in the (Java) test-compile phase -->
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<!-- Add src/main/scala to source path of Eclipse -->
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/scala</source>
</sources>
</configuration>
</execution>
<!-- Add src/test/scala to test source path of Eclipse -->
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/scala</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- to generate Eclipse artifacts for projects mixing Scala and Java -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<projectnatures>
<projectnature>org.scala-ide.sdt.core.scalanature</projectnature>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
</projectnatures>
<buildcommands>
<buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand>
</buildcommands>
<classpathContainers>
<classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER</classpathContainer>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
</classpathContainers>
<excludes>
<!-- in Eclipse, use scala-library, scala-compiler from the SCALA_CONTAINER rather than POM <dependency> -->
<exclude>org.scala-lang:scala-library</exclude>
<exclude>org.scala-lang:scala-compiler</exclude>
</excludes>
<sourceIncludes>
<sourceInclude>**/*.scala</sourceInclude>
<sourceInclude>**/*.java</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>
<!-- When run tests in the test phase, include .java and .scala source files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<includes>
<include>**/*.java</include>
<include>**/*.scala</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Clear the Scala IDE project settings by removing and adding back Scala Nature
I am using maven sql plugin. I am using the plugin to setup the my test db before executing integration tests. Here is my plugin configuration from my project pom. When I execute mvn clean install I expect the plugin goals to execute. But they are not getting executed. Any help will be appreciated. I am facing similar issue for aspectj plugin (configuration provided below).
My SQL plugin configuration:
<!-- Maven SQL Plugin for setting up test schema for integration tests -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies> <!-- specify the dependent JDBC driver here -->
<dependency>
<groupId>${jdbc.groupId}</groupId>
<artifactId>${jdbc.artifactId}</artifactId>
<version>${jdbc.version}</version>
</dependency>
</dependencies>
<!-- common configuration shared by all executions -->
<configuration>
<driver>org.hsqldb.jdbcDriver</driver>
<url>jdbc:hsqldb:sample</url>
<username>sa</username>
<password></password>
</configuration>
<executions>
<execution>
<id>create_db_schema</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<!-- specific configuration for this execution -->
<configuration>
<srcFiles>
<srcFile>src/test/resources/test-schema.sql</srcFile>
</srcFiles>
</configuration>
</execution>
<execution>
<id>shutdown_db_instance</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<sqlCommand>SHUTDOWN IMMEDIATELY</sqlCommand>
</configuration>
</execution>
</executions>
</plugin>
My aspectj plugin configuration:
<!-- AspectJ Compile-time waving for spring cross-store. -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<showWeaveInfo>true</showWeaveInfo>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-cross-store</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
Be sure that these plugins are not defined inside project/build/pluginManagement/plugins, but in project/build/plugins.
Only the latter are executed, those plugins will then will be checked with the pluginManagement for the final configuration.