From 38d07733d60b3f2f59e09d7d5145b734516cb0c6 Mon Sep 17 00:00:00 2001 From: Michael Karneim Date: Mon, 17 Jan 2022 12:30:14 +0100 Subject: [PATCH] Fix #172 - Support Java 17 record type --- README.md | 29 ++++++++++++++++-------- build.gradle | 4 +++- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9ea28c3..21c8311 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ For older versions and a *change log* please see the [release history page]. PojoBuilder *binaries* are available for download at [Sonatype OSS Maven Repository] and [Maven Central]. If you don't use any build automation tool that supports maven repos, -you might want to download the [`pojobuilder-4.2.3-jar-with-dependencies.jar`] to get PojoBuilder complete with all dependent libraries included. +you might want to download the [`pojobuilder-4.3.0-jar-with-dependencies.jar`] to get PojoBuilder complete with all dependent libraries included. How To Use ---------- @@ -206,6 +206,15 @@ public class FileFactory { ``` Have a look at [`FileBuilder.java`] to see the generated source code. +### Annotating a Record ### + +Beginning with PojoBuilder 4.3 you can annotate a Java 17 record type: + +```java +@GeneratePojoBuilder +public record MyRecord(int x, int y, String blah) {} +``` + ### Directives ### The following elements of [@GeneratePojoBuilder] can be used to configure the output of the code generation process. @@ -343,7 +352,7 @@ The `javac` compiler will auto-detect the presence of PojoBuilder if `pojobuilde For example: - javac -cp pojobuilder-4.2.3-jar-with-dependencies.jar Contact.java + javac -cp pojobuilder-4.3.0-jar-with-dependencies.jar Contact.java will generate a `ContactBuilder` if `Contact` is annotated with `@GeneratePojoBuilder`. @@ -356,7 +365,7 @@ Add the following to your project's `pom.xml` to configure the PojoBuilder annot net.karneim pojobuilder - 4.2.3 + 4.3.0 provided @@ -378,7 +387,7 @@ repositories { } dependencies { - compile 'net.karneim:pojobuilder:4.2.3' + compile 'net.karneim:pojobuilder:4.3.0' } ``` Please note that this not only adds the PojoBuilder and its dependencies to your compile-time class path but also to your run-time class path. @@ -396,8 +405,8 @@ configurations { } dependencies { - codeGeneration 'net.karneim:pojobuilder:4.2.3' - compileOnly 'net.karneim:pojobuilder:4.2.3:annotations' + codeGeneration 'net.karneim:pojobuilder:4.3.0' + compileOnly 'net.karneim:pojobuilder:4.3.0:annotations' } compileJava.classpath += configurations.codeGeneration compileTestJava.classpath += configurations.codeGeneration @@ -421,7 +430,7 @@ To make pojobuilder work again, replace the used dependency scope with `annotati ```groovy dependencies { - annotationProcessor 'net.karneim:pojobuilder:4.2.3' + annotationProcessor 'net.karneim:pojobuilder:4.3.0' } ``` @@ -459,7 +468,7 @@ Do the following to enable PojoBuilder for your Eclipse project: * Open your project's properties dialog * Navigate to "Java Build Path" tree node * Open the "Libraries" tab -* Add `pojobuilder-4.2.3-annotations.jar` to your project classpath +* Add `pojobuilder-4.3.0-annotations.jar` to your project classpath * Navigate to "Java Compiler / Annotation Processing" tree node * Check "Enable project specific settings" * Check "Enable annotation processing" @@ -468,7 +477,7 @@ Do the following to enable PojoBuilder for your Eclipse project: * Navigate to "Java Compiler / Annotation Processing / Factory Path" tree node * Check "Enable project specific settings" * Click "Add JARs..." -* Add `pojobuiler-4.2.3-jar-with-dependencies.jar` +* Add `pojobuiler-4.3.0-jar-with-dependencies.jar` * Click "OK" How To Build @@ -480,7 +489,7 @@ If you want to compile this project's sources yourself you can use Gradle (see [ [JavaWriter]: https://github.com/square/javawriter [Sonatype OSS Maven Repository]: https://oss.sonatype.org/content/repositories/releases/net/karneim/pojobuilder [Maven Central]: http://search.maven.org/#search|ga|1|a%3A%22pojobuilder%22 -[`pojobuilder-4.2.3-jar-with-dependencies.jar`]: https://oss.sonatype.org/content/repositories/releases/net/karneim/pojobuilder/4.2.3/pojobuilder-4.2.3-jar-with-dependencies.jar +[`pojobuilder-4.3.0-jar-with-dependencies.jar`]: https://oss.sonatype.org/content/repositories/releases/net/karneim/pojobuilder/4.3.0/pojobuilder-4.3.0-jar-with-dependencies.jar [javac documentation]: http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html#processing [@ConstructorProperties]: http://docs.oracle.com/javase/6/docs/api/java/beans/ConstructorProperties.html diff --git a/build.gradle b/build.gradle index 6eccad2..7921719 100644 --- a/build.gradle +++ b/build.gradle @@ -100,7 +100,9 @@ task dependenciesJar(type: Jar, dependsOn:['compileJava']) { archiveClassifier = "jar-with-dependencies" from files(sourceSets.main.output.classesDirs) from files(sourceSets.main.output.resourcesDir) - from {configurations.compile.collect {zipTree(it)}} + from { + configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) } + } into('META-INF/license') { from 'license' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 98b73a9..1e35bd6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-5.3-rc-2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists