Skip to content

Commit

Permalink
Merge pull request #868 from freefair/feature/docs-for-kts
Browse files Browse the repository at this point in the history
added kotlin dsl configurations to documentation
  • Loading branch information
larsgrefer authored Aug 27, 2023
2 parents 008312d + 822c29c commit 0712001
Show file tree
Hide file tree
Showing 13 changed files with 564 additions and 45 deletions.
8 changes: 8 additions & 0 deletions documentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ plugins {
id 'io.freefair.javadoc-links'
}

configurations {
asciidoctorExt
}

asciidoctor {
baseDirFollowsSourceDir()

attributes gradle_version: gradle.gradleVersion

configurations 'asciidoctorExt'

inputs.dir("src/docs/asciidoc")
}

Expand All @@ -22,6 +28,8 @@ dependencies {
javadocClasspath "org.jacoco:org.jacoco.ant:${org.gradle.testing.jacoco.plugins.JacocoPlugin.DEFAULT_JACOCO_VERSION}"
javadocClasspath "org.apache.maven.plugins:maven-plugin-plugin:3.9.0"
javadocClasspath 'net.sourceforge.plantuml:plantuml:1.2023.10'

asciidoctorExt "io.spring.asciidoctor:spring-asciidoctor-extensions-block-switch:0.6.2"
}

tasks.register("docsZip", Zip) {
Expand Down
123 changes: 115 additions & 8 deletions documentation/src/docs/asciidoc/_aspectj.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,67 @@ This plugin adds AspectJ support to the project, by adding a `aspectj` directory

Source contained in the `src/main/aspectj` directory will be compiled with `ajc` by the `compileAspectj` task.

[source,groovy]
--
[source, groovy, role="primary"]
.Groovy
----
dependencies {
implementation "org.aspectj:aspectjrt:1.9.8.RC3"
}
----
[source, kotlin, role="secondary"]
.Kotlin
----
dependencies {
implementation("org.aspectj:aspectjrt:1.9.8.RC3")
}
----
--

TIP: This is follows the same principles as the `groovy` and `scala` plugins.

Additional advices (the `-aspectpath`) can be declared as dependencies of the `aspect` configuration:

[source,groovy]
--
[source, groovy, role="primary"]
.Groovy
----
dependencies {
aspect project(":my-aspect")
testAspect "com.example.foo:bar-aspect:1.0.0"
}
----
[source, kotlin, role="secondary"]
.Kotlin
----
dependencies {
aspect(project(":my-aspect"))
testAspect("com.example.foo:bar-aspect:1.0.0")
}
----
--

Additional jars/classes which should be woven and added to the output as well (the `-inpath`)
can be declared as dependencies fo the `inpath` configuration:

[source,groovy]
--
[source, groovy, role="primary"]
.Groovy
----
dependencies {
inpath project(":my-lib")
testInpath "com.example.foo:bar-lib:1.0.0"
}
----
[source, kotlin, role="secondary"]
.Kotlin
----
dependencies {
inpath(project(":my-lib"))
testInpath("com.example.foo:bar-lib:1.0.0")
}
----
--

=== `io.freefair.aspectj.post-compile-weaving`

Expand All @@ -70,41 +102,75 @@ with an additional `ajc` action in order to perform post-compile-weaving.

The output of the compilation (`javac`, etc.) becomes the `-inpath` for `ajc`.

[source,groovy]
--
[source, groovy, role="primary"]
.Groovy
----
dependencies {
implementation "org.aspectj:aspectjrt:1.9.8.RC3"
}
----
[source, kotlin, role="secondary"]
.Kotlin
----
dependencies {
implementation("org.aspectj:aspectjrt:1.9.8.RC3")
}
----
--

Additional advices (the `-aspectpath`) can be declared as dependencies of the `aspect` configuration:

[source,groovy]
--
[source, groovy, role="primary"]
.Groovy
----
dependencies {
aspect project(":my-aspect")
testAspect "com.example.foo:bar-aspect:1.0.0"
}
----
[source, kotlin, role="secondary"]
.Kotlin
----
dependencies {
aspect(project(":my-aspect"))
testAspect("com.example.foo:bar-aspect:1.0.0")
}
----
--

Additional jars/classes which should be woven and added to the output as well (the `-inpath`)
can be declared as dependencies fo the `inpath` configuration:

[source,groovy]
--
[source, groovy, role="primary"]
.Groovy
----
dependencies {
inpath project(":my-lib")
testInpath "com.example.foo:bar-lib:1.0.0"
}
----
[source, kotlin, role="secondary"]
.Kotlin
----
dependencies {
inpath(project(":my-lib"))
testInpath("com.example.foo:bar-lib:1.0.0")
}
----
--

The `-classpath`, `-source` and `-target`
arguments of `ajc` are set automatically to the corresponding values taken from the compile task.
Additional `ajc` arguments can be configured using the `ajc.options.compilerArgs` property as shown below.

The following things are configurable:

[source,groovy]
--
[source, groovy, role="primary"]
.Groovy
----
compileJava {
ajc {
Expand All @@ -127,6 +193,31 @@ compileTestJava {
}
}
----
[source, kotlin, role="secondary"]
.Kotlin
----
tasks.compileJava {
configure<AjcAction> {
enabled = true //<1>
classpath //<2>
options {
aspectpath.setFrom(configurations.aspect) //<3>
compilerArgs = listOf("") //<4>
}
}
}
tasks.compileTestJava {
configure<AjcAction> {
enabled = true //<1>
classpath //<2>
options {
aspectpath.setFrom(configurations.testAspect) //<3>
compilerArgs = listOf("") //<4>
}
}
}
----
--
<1> Specifies if ajc should run at all. Defaults to `true`
<2> The classpath containing ajc itself (`aspectjtools.jar`). Inferred from the compile/runtime classpaths by default.
<3> The classpath containing additional advices to weave. This directly maps to the `-aspectpath` argument of ajc.
Expand All @@ -143,11 +234,27 @@ https://docs.gradle.org/{gradle_version}/javadoc/org/gradle/api/tasks/compile/Ab
task can be used to run
https://www.eclipse.org/aspectj/doc/released/devguide/ajc-ref.html[`ajc`].

[source,groovy]
--
[source, groovy, role="primary"]
.Groovy
----
task myAjcTask(type: io.freefair.gradle.plugins.aspectj.AspectjCompile) {
aspectjClasspath.setFrom configurations.aspectj
ajcOptions {
inpath = files()
aspectpath = files()
}
}
----
[source, kotlin, role="secondary"]
.Kotlin
----
tasks.register<AspectjCompile>("myAjcTask") {
aspectjClasspath.setFrom(configurations.aspectj)
ajcOptions {
inpath = files()
aspectpath = files()
}
}
----
--
Loading

0 comments on commit 0712001

Please sign in to comment.