How can I get AspectJ boot weaving running on Gradle (specifically libgdx builds)

So, I want to add some testing and registration features to my libgdx game.

So, I added the following main desktop dependencies gradle.

compile 'org.aspectj:aspectjweaver:1.8.2' compile "org.aspectj:aspectjrt:1.8.2" 

Initially, he did not find a dependency, but this was solved both by turning off the offline mode and closing and reopening my IntelliJ project (the Gradle sync button did not work).

My understanding is that the animator file must be loaded as a Java agent. So I found where it displays gradle, loaded it and added the following VM runtime configuration options

 -javaagent:/Users/daniel/.gradle/caches/modules-2/files-2.1/org.aspectj/aspectjweaver/1.8.2/4963c0bef4748d5ad039cc26c1ac32a082eb755e/aspectjweaver-1.8.2.jar 

Surprisingly, this gives me the following warning message

 objc[66447]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined. 

This message is missing without the -javaagent line.

I tried to run this example for the boot example. http://andrewclement.blogspot.co.uk/2009/02/load-time-weaving-basics.html

However, I do not need a separate reusable aspect, so I just created the base aop.xml file in the src directory with the following contents.

 <aspectj> <weaver options="-verbose"/> </aspectj> 

Obviously, nothing has been created for me yet, I just want to confirm that the setup works. There are enough differences between this tutorial and my target environment, which, I think, a lot can go wrong.

Actually, I don't mind if compilation time or class loading will take place if it works in the libgdx / gradle environment. I decided to look into the decision to load classes because of my unfamiliarity with the environment and the requirements of libgdx / gradle.

Thanx in advance.

Update : let's try to make my way through this http://www.breskeby.com/2010/02/using-gradle-with-aspectj/

... but the not-so-familiar iajc mentioned in the tutorial, and knowing how to use this in libgdx build scripts also seems complicated.

+6
source share
1 answer

I'm not going to implement a gradle implementation, but Maven is one using AspectJ. Obviously, you will have to customize / adapt to your needs. The following is an aspect of the bar.foo method with two parameters (String, Boolean) with advice @Around and a ProceedingJoinPoint . Any advice or pointcut can be implemented.

Java

 @Aspect @ajcPrivileged public class MyAspect { @Pointcut("execution(* bar.foo(String, Boolean)) && args(string, bool)") void foo(String string, Boolean bool) {} @Around(value = "loadFile(filePathName, toGray)", argNames = "filePathName, toGray") public MyReturnType foo(final ProceedingJoinPoint joinPoint, final String string, final Boolean bool) throws MyEx { //impl } } 

POM

See the Weave comment for third-party dependency to determine the third-party library that you want to bind.

 <project ..> .. <properties> <aspectj-maven-plugin.version>1.7</aspectj-maven-plugin.version> <aspectjrt.version>1.8.2</aspectjrt.version> .. </properties> <dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>${aspectjrt.version}</version> </dependency> .. </dependencies> <build> .. <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>${aspectj-maven-plugin.version}</version> <configuration> <complianceLevel>${java.version}</complianceLevel> <source>${java.version}</source> <target>${java.version}</target> <!-- Weave third party dependency --> <weaveDependencies> <weaveDependency> <groupId>yourThirdPartyDepGroupId</groupId> <artifactId>yourThirdPartyDepGroupIdArtifactId</artifactId> </weaveDependency> </weaveDependencies> </configuration> <!-- Weave on compile --> <executions> <execution> <goals> <goal>compile</goal> <goal>test-compile</goal> </goals> </execution> </executions> </plugin> </plugins> <pluginManagement> <plugins> <!--This plugin configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>${lifecycle-mapping.version}</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <versionRange>[1.7,)</versionRange> <goals> <goal>compile</goal> </goals> </pluginExecutionFilter> <action> <ignore></ignore> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </pluginManagement> </build> </project> 
+2
source

Source: https://habr.com/ru/post/974245/


All Articles