java - AspectJ module dependency with Maven - How get working the Inter-type declarations methods of a dependency module -
this situation:
i have maven project my-project-aj-dependency
composed 2 jar modules:
my-project-aj-dependencyjarwithaj
(where have inter-type declaration, seeahah()
method below inside aspectappwithaj_ahah.aj
)my-project-aj-dependencyjarwithoutaj
my problem use declared method defined in aspect of first module inside second module, missed something.
my poms configuration following:
maven project pom (my-project-aj-dependency
):
<?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"> <name>myprojectajdependency</name> <modelversion>4.0.0</modelversion> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependency</artifactid> <version>0.0.1-snapshot</version> <packaging>pom</packaging> <modules> <!-- <module>testmaven-ejb</module> --> <module>my-project-aj-dependencyjarwithaj</module> <module>my-project-aj-dependencyjarwithoutaj</module> </modules> <properties> <maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.source>1.7</maven.compiler.source> <aspectj.version>1.8.9</aspectj.version> </properties> <dependencymanagement> <dependencies> <dependency> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependencyjarwithaj</artifactid> <version>${project.version}</version> </dependency> <dependency> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependencyjarwithoutaj</artifactid> <version>${project.version}</version> </dependency> </dependencies> </dependencymanagement> <build> <pluginmanagement> <plugins> </plugins> </pluginmanagement> </build> </project>
maven module 1 pom (my-project-aj-dependencyjarwithaj
):
<?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/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependency</artifactid> <version>0.0.1-snapshot</version> </parent> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependencyjarwithaj</artifactid> <version>0.0.1-snapshot</version> <name>my-project-aj-dependencyjarwithaj</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> <dependencies> <dependency> <groupid>org.aspectj</groupid> <artifactid>aspectjrt</artifactid> <version>1.8.9</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <configuration> <source>${java-version}</source> <target>${java-version}</target> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-dependency-plugin</artifactid> <executions> <execution> <id>install</id> <phase>install</phase> <goals> <goal>sources</goal> </goals> </execution> </executions> </plugin> <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>aspectj-maven-plugin</artifactid> <!-- have use version 1.2 since version 1.3 not appear work itds --> <version>1.2</version> <dependencies> <!-- must use maven 2.0.9 or above or these ignored (see mng-2972) --> <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> <configuration> <outxml>true</outxml> <source>${java-version}</source> <target>${java-version}</target> </configuration> </plugin> </plugins> </build> </project>
maven module 2 pom (my-project-aj-dependencyjarwithoutaj
):
<?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/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependency</artifactid> <version>0.0.1-snapshot</version> </parent> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependencyjarwithoutaj</artifactid> <version>0.0.1-snapshot</version> <name>my-project-aj-dependencyjarwithoutaj</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> <dependencies> <dependency> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependencyjarwithaj</artifactid> <version>${project.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <configuration> <source>${java-version}</source> <target>${java-version}</target> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-dependency-plugin</artifactid> <executions> <execution> <id>install</id> <phase>install</phase> <goals> <goal>sources</goal> </goals> </execution> </executions> </plugin> <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>aspectj-maven-plugin</artifactid> <!-- have use version 1.2 since version 1.3 not appear work itds --> <version>1.2</version> <dependencies> <!-- must use maven 2.0.9 or above or these ignored (see mng-2972) --> <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> <configuration> <outxml>true</outxml> <source>${java-version}</source> <target>${java-version}</target> </configuration> </plugin> </plugins> </build> </project>
where appwithaj.java
is:
package org.my.project.aj.dependencyjarwithaj; public class appwithaj { public static void main( string[] args ){ system.out.println( "hello world!" ); } }
and appwithaj_ahah.aj
is:
package org.my.project.aj.dependencyjarwithaj; public aspect appwithaj_ahah { public string appwithaj.ahah(){ return "ahahahah!"; } }
and app.java
is:
package org.my.project.aj.dependencyjarwithoutaj; import org.my.project.aj.dependencyjarwithaj.appwithaj; public class app { public static void main( string[] args ) { system.out.println( "hello world! " + new appwithaj().ahah()); } }
your solution way complicated:
- the aspectj (aj) module needs aj maven plugin , dependency on aspectjrt. far, good.
- but declared aspect affects class within own module, extending via itd. there no need use aj compiler on pure java module calls method aj module. irrelevant called method created itd, other module looks normal java.
- consequently, non-aj module needs normal dependency on aj module because uses 1 of classes. aj runtime dependency transitive , should used automatically.
update:
you asked poms, here are.
root pom:
<?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/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependency</artifactid> <version>0.0.1-snapshot</version> <name>myprojectajdependency</name> <packaging>pom</packaging> <properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> <java.source-target.version>1.7</java.source-target.version> <aspectj.version>1.8.9</aspectj.version> </properties> <dependencymanagement> <dependencies> <dependency> <groupid>org.aspectj</groupid> <artifactid>aspectjrt</artifactid> <version>${aspectj.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependencyjarwithaj</artifactid> <version>${project.version}</version> </dependency> <dependency> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependencyjarwithoutaj</artifactid> <version>${project.version}</version> </dependency> </dependencies> </dependencymanagement> <build> <pluginmanagement> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.5.1</version> <configuration> <source>${java.source-target.version}</source> <target>${java.source-target.version}</target> <!-- important --> <useincrementalcompilation>false</useincrementalcompilation> </configuration> </plugin> <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>aspectj-maven-plugin</artifactid> <version>1.8</version> <configuration> <!--<showweaveinfo>true</showweaveinfo>--> <source>${java.source-target.version}</source> <target>${java.source-target.version}</target> <xlint>ignore</xlint> <compliancelevel>${java.source-target.version}</compliancelevel> <encoding>${project.build.sourceencoding}</encoding> <!--<verbose>true</verbose>--> <!--<warn>constructorname,packagedefaultmethod,deprecation,maskedcatchblocks,unusedlocals,unusedarguments,unusedimport</warn>--> </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> <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>exec-maven-plugin</artifactid> <version>1.4.0</version> </plugin> </plugins> </pluginmanagement> </build> <modules> <module>my-project-aj-dependencyjarwithaj</module> <module>my-project-aj-dependencyjarwithoutaj</module> </modules> </project>
module aspectj:
<?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/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependency</artifactid> <version>0.0.1-snapshot</version> </parent> <artifactid>my-project-aj-dependencyjarwithaj</artifactid> <build> <plugins> <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>aspectj-maven-plugin</artifactid> </plugin> </plugins> </build> <dependencies> <dependency> <groupid>org.aspectj</groupid> <artifactid>aspectjrt</artifactid> </dependency> </dependencies> </project>
plain java module:
<?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/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependency</artifactid> <version>0.0.1-snapshot</version> </parent> <artifactid>my-project-aj-dependencyjarwithoutaj</artifactid> <build> <plugins> <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>exec-maven-plugin</artifactid> <configuration> <mainclass>org.my.project.aj.dependencyjarwithoutaj.app</mainclass> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupid>com.madx</groupid> <artifactid>my-project-aj-dependencyjarwithaj</artifactid> </dependency> </dependencies> </project>
please note: have added exec maven plugin demo purposes, can this:
mvn clean install mvn -pl my-project-aj-dependencyjarwithoutaj exec:java
then should see on console:
(...) [info] --- exec-maven-plugin:1.4.0:java (default-cli) @ my-project-aj-dependencyjarwithoutaj --- hello world! ahahahah!
remove exec maven both root , plain java poms in order shorter poms.
Comments
Post a Comment