项目作者: sedovalx

项目描述 :
Gradle plugin for AspectJ binary weaving
高级语言: Kotlin
项目地址: git://github.com/sedovalx/gradle-aspectj-binary.git
创建时间: 2017-05-12T11:37:40Z
项目社区:https://github.com/sedovalx/gradle-aspectj-binary

开源协议:

下载


gradle-aspectj-binary

Disclamer: I don’t use this plugin in my projects anymore and currently don’t plan to support it in foreseeable future. In general, it works well but a bit outdated (Gradle, AspectJ versions). Feel free to fork it and adopt for your needs.

Build Status
Download

Gradle plugin for AspectJ binary weaving. It works similar to https://github.com/jcabi/jcabi-maven-plugin
doing the weaving on the weaving over already compiled classes. It is particularly helpful if the source code
is written in a language different from Java. For example, Kotlin, as it produces
fully compatible Java bytecode. It goes without saying that the plugin works for Java sources as well.

Requirements

  • The plugin uses AspectJ 1.9.2 for generating the bytecode. Please read there
    about supported JDK versions.
  • The plugin itself is compiled with openjdk8, so it requires JDK 8 or above to work.
  • The plugin uses Gradle 4.9 API so you need Gradle of that version or newer

Usage

Here is an example project in the examples folder. Basically you need to add the plugin to your build script

  1. buildscript {
  2. repositories {
  3. jcenter()
  4. }
  5. dependencies {
  6. classpath "com.github.sedovalx.gradle:gradle-aspectj-binary:$pluginVersion"
  7. }
  8. }
  9. apply plugin: 'com.github.sedovalx.gradle-aspectj-binary'

weaveClasses task becomes available after that. By default, if the java plugin is not disabled via
configuration (see below), there are pre-configured tasks dependencies:

  1. weaveClasses.dependsOn compileJava
  2. classes.dependsOn weaveClasses

so you can just run the build and have all your aspects in the main source set applied.

You need to weave both aspects and classes where aspects should be applied. So if you have aspect
classes in a project A and classes to be weaved in a project B you should add the weaveClasses task to the build
process of both projects. See the examples project for details.

Available configuration

The plugins can be configured with the following parameters

  1. aspectjBinary {
  2. applyJavaPlugin = true
  3. weaveClasses {
  4. ajcSourceSets = [project.sourceSets.main]
  5. outputDir = project.file(...)
  6. source = '1.7'
  7. target = '1.7'
  8. additionalAjcParams = ['-proceedOnError']
  9. writeToLog = true
  10. }
  11. }

Parameters:

  • applyJavaPlugin should the java plugin be applied with the aspectjBinary plugin. By default, it is applied but
    in some cases, for example Android projects, it is not desired. WARN: in this case, you must provide the ajcSourceSets
    and the outputDir property values by yourself as there is no default configuration for Android projects (any help is appreciated).
  • ajcSourceSets is a set of Gradle source sets to be weaved. By default, it includes the main source set only.
    Both compileClasspath and runtimeClasspath collections are extracted from each source set.
  • outputDir is a folder where the weaved classes are copied. By default, it is build/classes/java/main.
  • source has ‘1.7’ as default value and is passed as it is to the ajc compiler parameter
  • target has ‘1.7’ as default value and is passed as it is to the ajc compiler parameter
  • additionalAjcParams allows addition of arbitrary entries to the tail of the default AJC parameters
  • writeToLog has false as a default value and defines if ajc’s compile messages should
    affect the build process. In case of value is true all the messages are written in the
    build/ajc.log file and do not affect the build result. Otherwise, error or warning messages are
    printed in the build output and ajc errors (if any) break the build process.

Clean local build

The examples project depends on a version of the plugin. In case of a clean build no plugin version exists in
the repository. So I use a little bit hacky way to do the trick.

  1. $ echo "include 'plugin'" > settings.gradle
  2. $ ./gradlew clean :plugin:publishMavenJavaPublicationToMavenLocal
  3. $ echo "include 'plugin', 'examples', 'examples:aspects', 'examples:app'" > settings.gradle
  4. $ ./gradlew :examples:app:run