Skip to content

Commit

Permalink
fix #31 - provide example for delombok task with kotlin dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
franzbecker committed Feb 15, 2019
1 parent a4bf9d8 commit 1d80957
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 26 deletions.
30 changes: 4 additions & 26 deletions README.md
Expand Up @@ -61,32 +61,10 @@ When using Lombok in teams with no automated Eclipse provisioning this is quite
This plugin adds a task called `installLombok` to your Gradle build that uses the dependency that has already been added to the compile-only scope, verifies its integrity using SHA-256 and finally invokes the main class of the JAR. This greatly simplifies the installation process for each developer and makes sure that the same version is used across the team.

## Delombok support
The plugin offers basic support for delomboking. The `DelombokTask` is a simple `JavaExec` task that calls `delombok` on Lombok's main class and simplifies the setup of such a task in the build process:

import io.franzbecker.gradle.lombok.task.DelombokTask

task delombok(type: DelombokTask, dependsOn: compileJava) {
ext.outputDir = file("$buildDir/delombok")
outputs.dir(outputDir)
sourceSets.main.java.srcDirs.each {
inputs.dir(it)
args(it, "-d", outputDir)
}
doFirst {
outputDir.deleteDir()
}
}

task delombokHelp(type: DelombokTask) {
args "--help"
}

The class path for the `DelombokTask` includes, by default, the dependencies of the `compile` and `lombok` configurations only.
The plugin offers basic support for delomboking. The `DelombokTask` is a simple `JavaExec` task that calls `delombok` on Lombok's main class and simplifies the setup of such a task in the build process. It is not a ready to use task.

Note that if you want to generate JavaDoc you need to configure the `javadoc` task accordingly. For example:
Examples can be found at:

javadoc {
dependsOn delombok
source = delombok.outputDir
failOnError = false
}
[examples/delombok-gradle-groovy/build.gradle](examples/delombok-gradle-groovy/build.gradle) and<br/>
[examples/delombok-gradle-kotlin/build.gradle.kts](examples/delombok-gradle-kotlin/build.gradle.kts)
10 changes: 10 additions & 0 deletions examples/README.md
Expand Up @@ -19,3 +19,13 @@ Run it with:
./gradlew :delombok-gradle-groovy:javadoc

And open up [Greeting.html](delombok-gradle-groovy/build/docs/javadoc/com/example/Greeting.html) in your browser.

## delombok-gradle-kotlin

Demonstrates how the delombok task can be used to generate JavaDoc with Kotlin as the Gradle script language.

Run it with:

./gradlew :delombok-gradle-kotlin:javadoc

And open up [Greeting.html](delombok-gradle-kotlin/build/docs/javadoc/com/example/Greeting.html) in your browser.
26 changes: 26 additions & 0 deletions examples/delombok-gradle-kotlin/build.gradle.kts
@@ -0,0 +1,26 @@
import io.franzbecker.gradle.lombok.task.DelombokTask

tasks {

val delombok by registering(DelombokTask::class)
delombok {
dependsOn(compileJava)
val outputDir by extra { file("$buildDir/delombok") }
outputs.dir(outputDir)
sourceSets.getByName("main").java.srcDirs.forEach {
inputs.dir(it)
args(it, "-d", outputDir)
}
doFirst {
outputDir.delete()
}
}

javadoc {
dependsOn(delombok)
val outputDir: File by delombok.get().extra
source = fileTree(outputDir)
isFailOnError = false
}

}
@@ -0,0 +1,9 @@
package com.example;

import lombok.Data;

@Data
public class Greeting {

private String message;
}
1 change: 1 addition & 0 deletions examples/settings.gradle
Expand Up @@ -5,3 +5,4 @@ rootProject.name = 'examples'

include 'hello-world'
include 'delombok-gradle-groovy'
include 'delombok-gradle-kotlin'

0 comments on commit 1d80957

Please sign in to comment.