diff --git a/README.md b/README.md index efd829d..bf214e3 100644 --- a/README.md +++ b/README.md @@ -230,7 +230,9 @@ For example, if the properties file is in the Gradle project directory, add the ```gradle tasks.withType(JavaCompile) { - options.compilerArgs += [ "-Asemver.project.dir=$projectDir" ] + if (JavaVersion.current().isJava12Compatible()) { + options.compilerArgs += [ "-Asemver.project.dir=$projectDir" ] + } } ``` diff --git a/docs/README.html b/docs/README.html index aaea2f5..cf79f94 100644 --- a/docs/README.html +++ b/docs/README.html @@ -83,7 +83,7 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni

Semantic Version Annotation Processor

License (3-Clause BSD) release Maven Central Download
Known Vulnerabilities Quality Gate Status Build Status Build status CircleCI

-

An annotation processor that automatically generates a GeneratedVersion class based on a Mustache template and containing the semantic version (major, minor, patch, etc.) that is read from a Properties file or defined in the annotation.

+

An annotation processor that automatically generates a GeneratedVersion class based on a Mustache template and containing the semantic version (major, minor, patch, etc.) that is read from a Properties file or defined in the annotation.

This processor was inspired by Cédric Beust's version-processor and works well in conjunction with the Semantic Version Plugin for Gradle.

Table of Contents

  • Elements & Properties
  • -
  • Usage with Maven, Gradle, Kotlin and Kobalt -
  • Auto-Increment
  • Examples

    @@ -120,7 +118,7 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni public class A { // ...
    import net.thauvin.erik.semver.Version;
     
    @@ -132,9 +130,9 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
     version.minor=0
     version.patch=0
     version.prerelease=beta
    -

    View Example

    +

    View Examples

    Template

    -

    Upon running the annotation processor, a source file GeneratedVersion.java is automatically generated with static methods to access the semantic version data. The source is based on a fully customizable Mustache template.

    +

    Upon running the annotation processor, a source file GeneratedVersion.java is automatically generated with static methods to access the semantic version data. The source is based on a fully customizable Mustache template.

    To use your own template, simply create a version.mustache file in the project's root directory. The processor will automatically look for it.

    To specify your own template name, use:

    @Version(template = "version.mustache")
    @@ -427,66 +425,74 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
     

    ⚠️ keysPrefix is a new element staring in 1.1.0 and may break older versions when using custom property keys.
    A quick fix is to include keysPrefix="" in the annotation to remove the default version. prefix.

    -

    Usage with Maven, Gradle, Kotlin and Kobalt

    -

    Maven

    +

    Maven

    To install and run from Maven, configure an artifact as follows:

    -

    Please look at pom.xml in the Java example directory for a sample:

    +

    Please look at pom.xml in the examples/java directory for a sample:

    -

    Gradle

    -

    Class Generation

    -

    To install and run from Gradle, add the following to build.gradle:

    +

    Gradle

    +

    Class Generation

    +

    To install and run from Gradle, add the following to build.gradle:

    dependencies {
         annotationProcessor 'net.thauvin.erik:semver:1.2.0'
         implementation 'net.thauvin.erik:semver:1.2.0'
     }
     
    -

    The GeneratedVersion class will be automatically created in the build/generated directory upon compiling.

    -

    Class & Source Generation

    -

    In order to also incorporate the generated source code into the source tree, add the following to the very top of build.gradle:

    +

    The GeneratedVersion.java class will be automatically created in the build/generated directory upon compiling.

    +

    Please look at build.gradle in the examples/java directory for a sample.

    +

    Class & Source Generation

    +

    In order to also incorporate the generated source code into the source tree, add the following to the very top of build.gradle:

    compileJava.options.annotationProcessorGeneratedSourcesDirectory = file("${projectDir}/src/generated/java")
     
    -

    The GeneratedVersion.java file will now be located in src/generated.

    -

    Please look at build.gradle in the Java example directory for a sample.

    -

    Kotlin

    +

    The GeneratedVersion.java file will now be located in src/generated.

    +

    Java 12

    +

    When using properties file (version.properties) under Java 12+ and Gradle 5.4.1+, the directory containing the properties file must be specified using the semver.project.dir processor argument.

    +

    For example, if the properties file is in the Gradle project directory, add the following to build.gradle:

    +
    tasks.withType(JavaCompile) {
    +    if (JavaVersion.current().isJava12Compatible()) {
    +        options.compilerArgs += [ "-Asemver.project.dir=$projectDir" ]
    +    }
    +}
    +
    +

    Kotlin

    The annotation processor also supports Kotlin.

    To generate a Kotlin version file, simply specify the type as follows:

    - -

    The Kotlin default template implements the same static fields and functions as the Java template.

    -

    Kotlin & Gradle

    -

    To install and run from Gradle, add the following to build.gradle.kts:

    - +

    The Kotlin default template implements the same static fields and functions as the Java template.

    +

    Please look at the examples/kotlin project for a build.gradle.kts sample.

    +

    Kotlin & Gradle

    +

    To install and run from Gradle, add the following to build.gradle.kts:

    + +

    The arguments block is not required if kapt is configured to use the Gradle Worker API in gradle.properties:

    +

    This option will likely be enabled by default in the future, but is currently not working under Java 10+ see KT-26203.

    -

    Please look at the Kotlin example project for a build.gradle.kts sample.

    -

    Kobalt

    -

    To install and run from Kobalt, add the following to Build.kt:

    +

    Kobalt

    +

    To install and run from Kobalt, add the following to Build.kt:

    dependencies {
         apt("net.thauvin.erik:semver:1.2.0")
         compileOnly("net.thauvin.erik:semver:1.2.0")
     }
     
    -

    Please look at Build.kt in the Java example directory for a sample.

    +

    Please look at Build.kt in the examples/java directory for a sample.

    Auto-Increment

    Incrementing the version is best left to your favorite build system. For a solution using Gradle, please have a look at the Semver Version Plugin for Gradle.

    There are also full examples in both Java and Kotlin showing how to use both the plugin and annotation processor concurrently.

    diff --git a/examples/java/build.gradle b/examples/java/build.gradle index 41fdee3..20d7757 100644 --- a/examples/java/build.gradle +++ b/examples/java/build.gradle @@ -28,9 +28,10 @@ dependencies { implementation semverProcessor } -// For Java 12+ tasks.withType(JavaCompile) { - options.compilerArgs += [ "-Asemver.project.dir=$projectDir" ] + if (JavaVersion.current().isJava12Compatible()) { + options.compilerArgs += [ "-Asemver.project.dir=$projectDir" ] + } } task runExample(type: JavaExec) {