Added table of contents.
Added Maven example. Added Kotlin's kapt limitations, etc.
This commit is contained in:
parent
fbdd6661ea
commit
b175ad4f4c
2 changed files with 73 additions and 50 deletions
22
README.md
22
README.md
|
@ -191,11 +191,17 @@ To install and run from [Maven](https://maven.apache.org/), configure an artifac
|
|||
</dependency>
|
||||
```
|
||||
|
||||
Please look at [pom.xml](https://github.com/ethauvin/semver/blob/master/examples/java/pom.xml) in the [Java example](https://github.com/ethauvin/semver/tree/master/examples/java) directory for a sample:
|
||||
|
||||
```bash
|
||||
mvn compile exec:java
|
||||
```
|
||||
|
||||
### Gradle
|
||||
|
||||
#### Class Generation
|
||||
|
||||
To install and run from [Gradle](https://gradle.org/), add the following to the `build.gradle` file:
|
||||
To install and run from [Gradle](https://gradle.org/), add the following to `build.gradle`:
|
||||
|
||||
```gradle
|
||||
dependencies {
|
||||
|
@ -208,7 +214,7 @@ The `GeneratedVersion` class will be automatically created in the `build/generat
|
|||
|
||||
#### Class & Source Generation
|
||||
|
||||
In order to also incorporate the generated source code into the `source tree`, add the following to the very top of the `build.gradle` file:
|
||||
In order to also incorporate the generated source code into the `source tree`, add the following to the very top of `build.gradle`:
|
||||
|
||||
```gradle
|
||||
compileJava.options.annotationProcessorGeneratedSourcesDirectory = file("${projectDir}/src/generated/java")
|
||||
|
@ -216,7 +222,7 @@ compileJava.options.annotationProcessorGeneratedSourcesDirectory = file("${proje
|
|||
|
||||
The `GeneratedVersion.java` file will now be located in `src/generated`.
|
||||
|
||||
Please look at the [build.gradle](https://github.com/ethauvin/semver/blob/master/examples/java/build.gradle) file in the [Java example](https://github.com/ethauvin/semver/tree/master/examples/java) module directory for a sample.
|
||||
Please look at [build.gradle](https://github.com/ethauvin/semver/blob/master/examples/java/build.gradle) in the [Java example](https://github.com/ethauvin/semver/tree/master/examples/java) directory for a sample.
|
||||
|
||||
### Kotlin
|
||||
|
||||
|
@ -235,7 +241,7 @@ The [Kotlin default template](https://github.com/ethauvin/semver/blob/master/src
|
|||
|
||||
#### Kotlin & Gradle
|
||||
|
||||
To install and run from [Gradle](https://gradle.org/), add the following to the `build.gradle.kts` file:
|
||||
To install and run from [Gradle](https://gradle.org/), add the following to `build.gradle.kts`:
|
||||
|
||||
```kotlin
|
||||
var semverProcessor = "net.thauvin.erik:semver:1.2.0"
|
||||
|
@ -245,19 +251,19 @@ dependencies {
|
|||
compileOnly(semverProcessor)
|
||||
}
|
||||
```
|
||||
As of [Kotlin 1.2.30](https://blog.jetbrains.com/kotlin/2019/04/kotlin-1-3-30-released/#more-6991), when using `kapt` you must include the following to the `gradle.properties` file:
|
||||
As of [Kotlin 1.2.30](https://blog.jetbrains.com/kotlin/2019/04/kotlin-1-3-30-released/#more-6991), when using `kapt` you must include the following in `gradle.properties`:
|
||||
|
||||
```ini
|
||||
kapt.use.worker.api=true
|
||||
```
|
||||
|
||||
This option will likely be enabled by default in the future.
|
||||
This option will likely be enabled by default in the future, but is currently not working under Java 10/11 see [KT-26203](https://youtrack.jetbrains.net/issue/KT-26203).
|
||||
|
||||
Please look at the [Kotlin example](https://github.com/ethauvin/semver/tree/master/examples/kotlin) project for a [build.gradle.kts](https://github.com/ethauvin/semver/blob/master/examples/kotlin/build.gradle.kts) sample.
|
||||
|
||||
### Kobalt
|
||||
|
||||
To install and run from [Kobalt](https://beust.com/kobalt/), add the following to the `Build.kt` file:
|
||||
To install and run from [Kobalt](https://beust.com/kobalt/), add the following to `Build.kt`:
|
||||
|
||||
```gradle
|
||||
dependencies {
|
||||
|
@ -266,7 +272,7 @@ dependencies {
|
|||
}
|
||||
```
|
||||
|
||||
Please look at the [Build.kt](https://github.com/ethauvin/semver/blob/master/examples/java/kobalt/src/Build.kt) file in the [Java example](https://github.com/ethauvin/semver/tree/master/examples/java) module directory for a sample.
|
||||
Please look at [Build.kt](https://github.com/ethauvin/semver/blob/master/examples/java/kobalt/src/Build.kt) in the [Java example](https://github.com/ethauvin/semver/tree/master/examples/java) directory for a sample.
|
||||
|
||||
|
||||
## Auto-Increment
|
||||
|
|
101
docs/README.html
101
docs/README.html
|
@ -85,6 +85,31 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
|
|||
<a href="https://snyk.io/test/github/ethauvin/semver?targetFile=build.gradle"><img src="https://snyk.io/test/github/ethauvin/semver/badge.svg?targetFile=build.gradle" alt="Known Vulnerabilities" /></a> <a href="https://sonarcloud.io/dashboard?id=ethauvin_semver"><img src="https://sonarcloud.io/api/project_badges/measure?project=ethauvin_semver&metric=alert_status" alt="Quality Gate Status" /></a> <a href="https://travis-ci.org/ethauvin/semver"><img src="https://travis-ci.org/ethauvin/semver.svg?branch=master" alt="Build Status" /></a> <a href="https://ci.appveyor.com/project/ethauvin/semver"><img src="https://ci.appveyor.com/api/projects/status/nbv4mxd1gpxtx69o?svg=true" alt="Build status" /></a> <a href="https://circleci.com/gh/ethauvin/semver/tree/master"><img src="https://circleci.com/gh/ethauvin/semver/tree/master.svg?style=shield" alt="CircleCI" /></a></p>
|
||||
<p>An <a href="https://docs.oracle.com/javase/8/docs/api/javax/annotation/processing/Processor.html">annotation processor</a> that automatically generates a <code>GeneratedVersion</code> class based on a <a href="https://mustache.github.io/">Mustache</a> template and containing the <a href="http://semver.org/">semantic version</a> (major, minor, patch, etc.) that is read from a <code>Properties</code> file or defined in the <a href="https://docs.oracle.com/javase/tutorial/java/annotations/basics.html">annotation</a>.</p>
|
||||
<p>This processor was inspired by Cédric Beust's <a href="https://github.com/cbeust/version-processor">version-processor</a> and works well in conjunction with the <a href="https://github.com/ethauvin/semver-gradle"><strong>Semantic Version Plugin for Gradle</strong></a>.</p>
|
||||
<h2 id="table-of-contents">Table of Contents</h2>
|
||||
<ul>
|
||||
<li><a href="#examples">Examples</a></li>
|
||||
<li><a href="#template">Template</a>
|
||||
<ul>
|
||||
<li><a href="#default-template">Default Template</a></li>
|
||||
<li><a href="#custom-template">Custom Template</a></li>
|
||||
</ul></li>
|
||||
<li><a href="#elements---properties">Elements & Properties</a></li>
|
||||
<li><a href="#usage-with-maven--gradle--kotlin-and-kobalt">Usage with Maven, Gradle, Kotlin and Kobalt</a>
|
||||
<ul>
|
||||
<li><a href="#maven">Maven</a></li>
|
||||
<li><a href="#gradle">Gradle</a>
|
||||
<ul>
|
||||
<li><a href="#class-generation">Class Generation</a></li>
|
||||
<li><a href="#class---source-generation">Class & Source Generation</a></li>
|
||||
</ul></li>
|
||||
<li><a href="#kotlin">Kotlin</a>
|
||||
<ul>
|
||||
<li><a href="#kotlin---gradle">Kotlin & Gradle</a></li>
|
||||
</ul></li>
|
||||
<li><a href="#kobalt">Kobalt</a></li>
|
||||
</ul></li>
|
||||
<li><a href="#auto-increment">Auto-Increment</a></li>
|
||||
</ul>
|
||||
<h2 id="examples">Examples</h2>
|
||||
<ul>
|
||||
<li>Using annotation elements:</li>
|
||||
|
@ -116,7 +141,7 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
|
|||
<a class="sourceLine" id="cb4-2" title="2"><span class="kw">public</span> <span class="kw">class</span> A {</a>
|
||||
<a class="sourceLine" id="cb4-3" title="3"><span class="co">// ...</span></a></code></pre></div>
|
||||
<h3 id="default-template">Default Template</h3>
|
||||
<p>The <a href="https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache">default template</a> implements the following static fields:</p>
|
||||
<p>The <a href="https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache">default template</a> implements the following static variables:</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr class="header">
|
||||
|
@ -183,28 +208,6 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>And the following methods/functions:</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr class="header">
|
||||
<th style="text-align: left;">Method</th>
|
||||
<th style="text-align: left;">Description</th>
|
||||
<th style="text-align: left;">Example</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="odd">
|
||||
<td style="text-align: left;"><code>preReleaseWithPrefix()</code></td>
|
||||
<td style="text-align: left;">Returns the pre-release with a prefix, <code>-</code> by default.</td>
|
||||
<td style="text-align: left;"><code>-alpha</code></td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td style="text-align: left;"><code>buildMetaWithPrefix()</code></td>
|
||||
<td style="text-align: left;">Returns the build metadata with a prefix, <code>+</code> by default.</td>
|
||||
<td style="text-align: left;"><code>+001</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h3 id="custom-template">Custom Template</h3>
|
||||
<p>A very simple custom template might look something like:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode java"><code class="sourceCode java"><a class="sourceLine" id="cb5-1" title="1"><span class="co">/* version.mustache */</span></a>
|
||||
|
@ -215,12 +218,8 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
|
|||
<a class="sourceLine" id="cb5-6" title="6"><span class="kw">public</span> <span class="dt">final</span> <span class="kw">class</span> {{className}} {</a>
|
||||
<a class="sourceLine" id="cb5-7" title="7"> <span class="kw">public</span> <span class="dt">final</span> <span class="dt">static</span> <span class="bu">String</span> PROJECT = <span class="st">"{{project}}"</span>;</a>
|
||||
<a class="sourceLine" id="cb5-8" title="8"> <span class="kw">public</span> <span class="dt">final</span> <span class="dt">static</span> <span class="bu">Date</span> DATE = <span class="kw">new</span> <span class="bu">Date</span>({{epoch}}L);</a>
|
||||
<a class="sourceLine" id="cb5-9" title="9"> <span class="kw">public</span> <span class="dt">final</span> <span class="dt">static</span> <span class="dt">int</span> MAJOR = {{major}};</a>
|
||||
<a class="sourceLine" id="cb5-10" title="10"> <span class="kw">public</span> <span class="dt">final</span> <span class="dt">static</span> <span class="dt">int</span> MINOR = {{minor}};</a>
|
||||
<a class="sourceLine" id="cb5-11" title="11"> <span class="kw">public</span> <span class="dt">final</span> <span class="dt">static</span> <span class="dt">int</span> PATCH = {{patch}};</a>
|
||||
<a class="sourceLine" id="cb5-12" title="12"> <span class="kw">public</span> <span class="dt">final</span> <span class="dt">static</span> <span class="bu">String</span> PRERELEASE = <span class="st">"{{preRelease}}"</span>;</a>
|
||||
<a class="sourceLine" id="cb5-13" title="13"> <span class="kw">public</span> <span class="dt">final</span> <span class="dt">static</span> <span class="bu">String</span> BUILDMETA = <span class="st">"{{buildMeta}}"</span>;</a>
|
||||
<a class="sourceLine" id="cb5-14" title="14">}</a></code></pre></div>
|
||||
<a class="sourceLine" id="cb5-9" title="9"> <span class="kw">public</span> <span class="dt">final</span> <span class="dt">static</span> <span class="bu">String</span> VERSION = <span class="st">"{{semver}}"</span>;</a>
|
||||
<a class="sourceLine" id="cb5-10" title="10">}</a></code></pre></div>
|
||||
<p>The mustache variables automatically filled in by the processor are:</p>
|
||||
<table>
|
||||
<thead>
|
||||
|
@ -291,6 +290,11 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
|
|||
<td style="text-align: left;">The version separator.</td>
|
||||
<td style="text-align: left;"><code>String</code></td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td style="text-align: left;"><code>{{semver}}</code> or <code>{{version}}</code></td>
|
||||
<td style="text-align: left;">The full semantic version.</td>
|
||||
<td style="text-align: left;"><code>String</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Please also look at this <a href="https://github.com/ethauvin/mobibot/blob/master/version.mustache">example</a> using <a href="https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html"><code>java.time</code></a></p>
|
||||
|
@ -423,7 +427,7 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
|
|||
<p><span class="emoji" data-emoji="warning">⚠️</span> <code>keysPrefix</code> is a new element staring in <code>1.1.0</code> and may break older versions when using custom property keys.<br />
|
||||
<span class="emoji" data-emoji="zap">⚡</span> A quick fix is to include <code>keysPrefix=""</code> in the annotation to remove the default <code>version.</code> prefix.</p>
|
||||
</blockquote>
|
||||
<h2 id="usage-with-maven-grail-kobalt-and-kotlin">Usage with Maven, Grail, Kobalt and Kotlin</h2>
|
||||
<h2 id="usage-with-maven-gradle-kotlin-and-kobalt">Usage with Maven, Gradle, Kotlin and Kobalt</h2>
|
||||
<h3 id="maven">Maven</h3>
|
||||
<p>To install and run from <a href="https://maven.apache.org/">Maven</a>, configure an artifact as follows:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode xml"><code class="sourceCode xml"><a class="sourceLine" id="cb8-1" title="1"><span class="kw"><dependency></span></a>
|
||||
|
@ -431,9 +435,11 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
|
|||
<a class="sourceLine" id="cb8-3" title="3"> <span class="kw"><artifactId></span>semver<span class="kw"></artifactId></span></a>
|
||||
<a class="sourceLine" id="cb8-4" title="4"> <span class="kw"><version></span>1.2.0<span class="kw"></version></span></a>
|
||||
<a class="sourceLine" id="cb8-5" title="5"><span class="kw"></dependency></span></a></code></pre></div>
|
||||
<p>Please look at <a href="https://github.com/ethauvin/semver/blob/master/examples/java/pom.xml">pom.xml</a> in the <a href="https://github.com/ethauvin/semver/tree/master/examples/java">Java example</a> directory for a sample:</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb9-1" title="1"><span class="ex">mvn</span> compile exec:java</a></code></pre></div>
|
||||
<h3 id="gradle">Gradle</h3>
|
||||
<h4 id="class-generation">Class Generation</h4>
|
||||
<p>To install and run from <a href="https://gradle.org/">Gradle</a>, add the following to the <code>build.gradle</code> file:</p>
|
||||
<p>To install and run from <a href="https://gradle.org/">Gradle</a>, add the following to <code>build.gradle</code>:</p>
|
||||
<pre class="gradle"><code>dependencies {
|
||||
annotationProcessor 'net.thauvin.erik:semver:1.2.0'
|
||||
compileOnly 'net.thauvin.erik:semver:1.2.0'
|
||||
|
@ -441,19 +447,11 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
|
|||
</code></pre>
|
||||
<p>The <code>GeneratedVersion</code> class will be automatically created in the <code>build/generated</code> directory upon compiling.</p>
|
||||
<h4 id="class--source-generation">Class & Source Generation</h4>
|
||||
<p>In order to also incorporate the generated source code into the <code>source tree</code>, add the following to the very top of the <code>build.gradle</code> file:</p>
|
||||
<p>In order to also incorporate the generated source code into the <code>source tree</code>, add the following to the very top of <code>build.gradle</code>:</p>
|
||||
<pre class="gradle"><code>compileJava.options.annotationProcessorGeneratedSourcesDirectory = file("${projectDir}/src/generated/java")
|
||||
</code></pre>
|
||||
<p>The <code>GeneratedVersion.java</code> file will now be located in <code>src/generated</code>.</p>
|
||||
<p>Please look at the <a href="https://github.com/ethauvin/semver/blob/master/examples/java/build.gradle">build.gradle</a> file in the <a href="https://github.com/ethauvin/semver/tree/master/examples/java">Java example</a> module directory for a sample.</p>
|
||||
<h3 id="kobalt">Kobalt</h3>
|
||||
<p>To install and run from <a href="https://beust.com/kobalt/">Kobalt</a>, add the following to the <code>Build.kt</code> file:</p>
|
||||
<pre class="gradle"><code>dependencies {
|
||||
apt("net.thauvin.erik:semver:1.2.0")
|
||||
compileOnly("net.thauvin.erik:semver:1.2.0")
|
||||
}
|
||||
</code></pre>
|
||||
<p>Please look at the <a href="https://github.com/ethauvin/semver/blob/master/examples/java/kobalt/src/Build.kt">Build.kt</a> file in the <a href="https://github.com/ethauvin/semver/tree/master/examples/java">Java example</a> module directory for a sample.</p>
|
||||
<p>Please look at <a href="https://github.com/ethauvin/semver/blob/master/examples/java/build.gradle">build.gradle</a> in the <a href="https://github.com/ethauvin/semver/tree/master/examples/java">Java example</a> directory for a sample.</p>
|
||||
<h3 id="kotlin">Kotlin</h3>
|
||||
<p>The annotation processor also supports <a href="https://kotlinlang.org/">Kotlin</a>.</p>
|
||||
<p>To generate a Kotlin version file, simply specify the <code>type</code> as follows:</p>
|
||||
|
@ -463,7 +461,26 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
|
|||
<a class="sourceLine" id="cb12-4" title="4"><span class="kw">open</span> <span class="kw">class</span> Main {</a>
|
||||
<a class="sourceLine" id="cb12-5" title="5"><span class="co">// ...</span></a></code></pre></div>
|
||||
<p>The <a href="https://github.com/ethauvin/semver/blob/master/src/main/resources/semver-kt.mustache">Kotlin default template</a> implements the same static fields and functions as the <a href="#default-template">Java template</a>.</p>
|
||||
<p>Please look at the <a href="https://github.com/ethauvin/semver/tree/master/examples/kotlin">Kotlin example</a> project for samples on using Gradle (<a href="https://github.com/ethauvin/semver/blob/master/examples/kotlin/build.gradle.kts">build.gradle.kts</a>) and Kobalt (<a href="https://github.com/ethauvin/semver/blob/master/examples/java/kobalt/src/Build.kt">Build.kt</a>).</p>
|
||||
<h4 id="kotlin--gradle">Kotlin & Gradle</h4>
|
||||
<p>To install and run from <a href="https://gradle.org/">Gradle</a>, add the following to <code>build.gradle.kts</code>:</p>
|
||||
<div class="sourceCode" id="cb13"><pre class="sourceCode kotlin"><code class="sourceCode kotlin"><a class="sourceLine" id="cb13-1" title="1"><span class="kw">var</span> <span class="va">semverProcessor</span> = <span class="st">"net.thauvin.erik:semver:1.2.0"</span></a>
|
||||
<a class="sourceLine" id="cb13-2" title="2"></a>
|
||||
<a class="sourceLine" id="cb13-3" title="3">dependencies {</a>
|
||||
<a class="sourceLine" id="cb13-4" title="4"> kapt(semverProcessor)</a>
|
||||
<a class="sourceLine" id="cb13-5" title="5"> compileOnly(semverProcessor)</a>
|
||||
<a class="sourceLine" id="cb13-6" title="6">}</a></code></pre></div>
|
||||
<p>As of <a href="https://blog.jetbrains.com/kotlin/2019/04/kotlin-1-3-30-released/#more-6991">Kotlin 1.2.30</a>, when using <code>kapt</code> you must include the following in <code>gradle.properties</code>:</p>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode ini"><code class="sourceCode ini"><a class="sourceLine" id="cb14-1" title="1"><span class="dt">kapt.use.worker.api</span><span class="ot">=</span><span class="kw">true</span></a></code></pre></div>
|
||||
<p>This option will likely be enabled by default in the future, but is currently not working under Java 10/11 see <a href="https://youtrack.jetbrains.net/issue/KT-26203">KT-26203</a>.</p>
|
||||
<p>Please look at the <a href="https://github.com/ethauvin/semver/tree/master/examples/kotlin">Kotlin example</a> project for a <a href="https://github.com/ethauvin/semver/blob/master/examples/kotlin/build.gradle.kts">build.gradle.kts</a> sample.</p>
|
||||
<h3 id="kobalt">Kobalt</h3>
|
||||
<p>To install and run from <a href="https://beust.com/kobalt/">Kobalt</a>, add the following to <code>Build.kt</code>:</p>
|
||||
<pre class="gradle"><code>dependencies {
|
||||
apt("net.thauvin.erik:semver:1.2.0")
|
||||
compileOnly("net.thauvin.erik:semver:1.2.0")
|
||||
}
|
||||
</code></pre>
|
||||
<p>Please look at <a href="https://github.com/ethauvin/semver/blob/master/examples/java/kobalt/src/Build.kt">Build.kt</a> in the <a href="https://github.com/ethauvin/semver/tree/master/examples/java">Java example</a> directory for a sample.</p>
|
||||
<h2 id="auto-increment">Auto-Increment</h2>
|
||||
<p>Incrementing the version is best left to your favorite build system. For a solution using Gradle, please have a look at the <a href="https://github.com/ethauvin/semver-gradle"><strong>Semver Version Plugin for Gradle</strong></a>.</p>
|
||||
<p>There are also full <a href="https://github.com/ethauvin/semver-gradle/tree/master/examples/annotation-processor">examples</a> in both <a href="https://github.com/ethauvin/semver-gradle/tree/master/examples/annotation-processor/java">Java</a> and <a href="https://github.com/ethauvin/semver-gradle/tree/master/examples/annotation-processor/kotlin">Kotlin</a> showing how to use both the plugin and annotation processor concurrently.</p>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue