Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit e948314

Browse files
Fixed gradle project setup (including ensuring unit tests are run), updated readme
1 parent 7915ba4 commit e948314

File tree

12 files changed

+83
-24
lines changed

12 files changed

+83
-24
lines changed

README.md

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,55 @@ This project aims to be a minimal viable replacement for the Lombok @Builder plu
66
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
77

88
## Usage
9-
TODO: gradle and maven
9+
#### Import `kotlin-builder-annotation` and `kotlin-builder-processor`
10+
And configure the [Kotlin annotation processor (kapt)](https://kotlinlang.org/docs/reference/kapt.html).
11+
##### Gradle
12+
```gradle
13+
...
14+
apply plugin: 'kotlin-kapt'
15+
...
16+
dependencies {
17+
...
18+
implementation 'com.thinkinglogic.builder:kotlin-builder-annotation:1.0.2'
19+
kapt 'com.thinkinglogic.builder:kotlin-builder-processor:1.0.2'
20+
}
21+
```
22+
##### Maven
23+
```maven
24+
...
25+
<dependencies>
26+
<dependency>
27+
<groupId>com.thinkinglogic.builder</groupId>
28+
<artifactId>kotlin-builder-annotation</artifactId>
29+
<version>1.0.2</version>
30+
</dependency>
31+
...
32+
</dependencies>
33+
...
34+
<execution>
35+
<id>kapt</id>
36+
<goals>
37+
<goal>kapt</goal>
38+
</goals>
39+
<configuration>
40+
<sourceDirs>
41+
<sourceDir>src/main/kotlin</sourceDir>
42+
<sourceDir>src/main/java</sourceDir>
43+
</sourceDirs>
44+
<annotationProcessorPaths>
45+
<!-- Specify your annotation processors here. -->
46+
<annotationProcessorPath>
47+
<groupId>com.thinkinglogic.builder</groupId>
48+
<artifactId>kotlin-builder-processor</artifactId>
49+
<version>1.0.2</version>
50+
</annotationProcessorPath>
51+
</annotationProcessorPaths>
52+
</configuration>
53+
</execution>
1054
11-
#### Annotate your class with the @Builder annotation
55+
```
56+
57+
#### Annotate your class(es) with the @Builder annotation
1258
```kotlin
1359
import com.thinkinglogic.builder.annotation.Builder
1460

@@ -20,8 +66,8 @@ data class MyDataClass(
2066
```
2167
That's it! Client code can now use a builder to construct instances of your class.
2268

23-
Unlike Lombok there's no bytecode manipulation, so we don't have a `MyDataClass.builder()` static method.
24-
Instead we create a `new MyDataClassBuilder()`:
69+
Unlike Lombok there's no bytecode manipulation, so we don't expose a `MyDataClass.builder()` static method.
70+
Instead clients create a `new MyDataClassBuilder()`, for instance:
2571

2672
```java
2773
public class MyDataFactory {
@@ -72,7 +118,7 @@ data class MyDataClass(
72118
```
73119

74120
#### Mutable collections
75-
Information about the mutability of collections and maps is lost during compilation, so there is a `@Mutable` annotation:
121+
Information about the mutability of collections and maps is lost during compilation, so there is an `@Mutable` annotation:
76122
```kotlin
77123
import com.thinkinglogic.builder.annotation.Builder
78124
import com.thinkinglogic.builder.annotation.Mutable
@@ -85,7 +131,7 @@ data class MyDataClass(
85131
```
86132

87133
#### Constructor parameters
88-
The `@Builder` annotation should be placed on a constructor instead of the class if you have constructor-only parameters:
134+
The `@Builder` annotation may be placed on a constructor instead of the class - useful if you have constructor-only parameters:
89135
```kotlin
90136
import com.thinkinglogic.builder.annotation.Builder
91137

@@ -99,7 +145,7 @@ constructor(
99145
val fullName = "$forename $surname"
100146
}
101147
```
102-
148+
Examples of all of the above may be found in the [kotlin-builder-example-usage](tree/develop/kotlin-builder-example-usage/src/main/kotlin/com/thinkinglogic/example) project.
103149
## License
104150
This software is Licenced under the [MIT License](LICENSE.md).
105151

build.gradle

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
buildscript {
2-
ext.kotlin_version = '1.2.60'
2+
ext.kotlin_version = '1.2.71'
3+
ext.kotlintest_version = '3.1.10'
4+
ext.junit_jupiter_version = '5.3.1'
35

46
repositories {
57
mavenCentral()
@@ -12,20 +14,19 @@ buildscript {
1214
}
1315
}
1416

15-
allprojects {
16-
group = 'com.thinkinglogic'
17-
version = '1.0.1'
18-
}
1917
/*
2018
* to publish:
2119
* gradle clean publish bintrayUpload
2220
*/
2321

2422
allprojects {
23+
group = 'com.thinkinglogic.builder'
24+
version = '1.0.3'
2525
apply plugin: "kotlin"
2626

2727
repositories {
2828
mavenCentral()
29+
jcenter()
2930
}
3031

3132
compileKotlin {
@@ -44,6 +45,13 @@ allprojects {
4445

4546
dependencies {
4647
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
48+
testCompile "org.junit.jupiter:junit-jupiter-engine:$junit_jupiter_version"
49+
testCompile "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version"
50+
testCompile "io.kotlintest:kotlintest-runner-junit5:$kotlintest_version"
51+
testCompile "io.kotlintest:kotlintest-core:$kotlintest_version"
4752
}
4853

54+
test {
55+
useJUnitPlatform()
56+
}
4957
}

kotlin-builder-annotation/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ task javadocJar(type: Jar) {
1818
publishing {
1919
publications {
2020
MyPublication(MavenPublication) {
21-
artifactId = 'kotlin-builder-annotation'
21+
groupId 'com.thinkinglogic.builder'
22+
artifactId 'kotlin-builder-annotation'
2223
from components.java
2324
artifact sourcesJar
2425
artifact javadocJar
@@ -61,6 +62,7 @@ javadoc {
6162
options.addBooleanOption('html4', true)
6263
}
6364
}
65+
/* see: https://github.com/bintray/gradle-bintray-plugin */
6466
bintray {
6567
user = System.getenv('BINTRAY_USER')
6668
key = System.getenv('BINTRAY_API_KEY')
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
apply plugin: 'kotlin-kapt'
22

33
dependencies {
4-
compile project(':kotlin-builder-annotation')
5-
6-
kapt project(':kotlin-builder-processor')
7-
4+
implementation project(':kotlin-builder-annotation')
85
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
96
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
107

11-
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.2.0'
12-
testCompile group: 'com.willowtreeapps.assertk', name: 'assertk', version: '0.10'
13-
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.10.0'
8+
kapt project(':kotlin-builder-processor')
9+
10+
testCompile "org.assertj:assertj-core:3.10.0"
11+
testCompile "com.willowtreeapps.assertk:assertk:0.10"
1412

1513
}

kotlin-builder-example-usage/src/main/kotlin/com/thinkinglogic/example/ArraysDataClass.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ data class ArraysDataClass(
1414
val arrayOfDates: Array<LocalDate>
1515

1616
) {
17+
// Due to the way the JVM uses instance equality for arrays, we should override equals and hashcode
1718
override fun equals(other: Any?): Boolean {
1819
if (this === other) return true
1920
if (javaClass != other?.javaClass) return false

kotlin-builder-example-usage/src/main/kotlin/com/thinkinglogic/example/CollectionsDataClass.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ data class CollectionsDataClass(
1414
val collectionOfDates: Collection<LocalDate>,
1515
@NullableType val mapOfStringToNullableDates: Map<String, LocalDate?>,
1616
val treeMap: TreeMap<String, LocalDate>
17-
1817
)

kotlin-builder-example-usage/src/test/java/com/thinkinglogic/example/SimpleDataClassJavaTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void builderShouldRejectNullValueForRequiredFields() {
1515
// when
1616
Throwable exception = catchThrowable(() -> builder.notNullString(null));
1717

18+
// then
1819
then(exception)
1920
.isInstanceOf(IllegalArgumentException.class)
2021
.hasMessageContaining("notNullString");

kotlin-builder-example-usage/src/test/kotlin/com/thinkinglogic/example/ArraysDataClassTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal class ArraysDataClassTest {
2222
.arrayOfDates(expected.arrayOfDates)
2323
.arrayOfLongs(expected.arrayOfLongs)
2424
.arrayOfStrings(expected.arrayOfStrings)
25+
.arrayOfNullableStrings(expected.arrayOfNullableStrings)
2526
.arrayOfListOfStrings(expected.arrayOfListOfStrings)
2627
.build()
2728

kotlin-builder-example-usage/src/test/kotlin/com/thinkinglogic/example/CollectionsDataClassTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal class CollectionsDataClassTest {
2626
.collectionOfDates(expected.collectionOfDates)
2727
.listOfStrings(expected.listOfStrings)
2828
.setOfLongs(expected.setOfLongs)
29+
.setOfNullableLongs(expected.setOfNullableLongs)
2930
.treeMap(expected.treeMap)
3031
.mapOfStringToNullableDates(expected.mapOfStringToNullableDates)
3132
.build()

kotlin-builder-example-usage/src/test/kotlin/com/thinkinglogic/example/SimpleDataClassTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ internal class SimpleDataClassTest {
4646

4747
// when
4848
val actual = SimpleDataClassBuilder()
49+
.notNullString(expected.notNullString)
4950
.notNullLong(expected.notNullLong)
5051
.nullableLong(expected.nullableLong)
5152
.date(expected.date)

kotlin-builder-processor/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ task javadocJar(type: Jar) {
2424
publishing {
2525
publications {
2626
MyPublication(MavenPublication) {
27-
artifactId = 'kotlin-builder-processor'
27+
groupId 'com.thinkinglogic.builder'
28+
artifactId 'kotlin-builder-processor'
2829
from components.java
2930
artifact sourcesJar
3031
artifact javadocJar
@@ -67,7 +68,7 @@ javadoc {
6768
options.addBooleanOption('html4', true)
6869
}
6970
}
70-
71+
/* see: https://github.com/bintray/gradle-bintray-plugin */
7172
bintray {
7273
user = System.getenv('BINTRAY_USER')
7374
key = System.getenv('BINTRAY_API_KEY')

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
rootProject.name = 'kotlin-builder-annotation-parent'
2-
include ':kotlin-builder-annotation', ':kotlin-builder-processor', ':example-usage'
2+
include ':kotlin-builder-annotation', ':kotlin-builder-processor', ':kotlin-builder-example-usage'

0 commit comments

Comments
 (0)