Closed vostapets closed 6 years ago
Seems that Oracle removed the @Generated annotation from Java 9.
Guess we have to substitute it with javax.annotation.processing.Generated for Java 9+.
QueryDsl, autovalue and others have the same issue: https://github.com/querydsl/querydsl/issues/2242
Thank you. I checked auto-value. They fixed for the latest version. https://github.com/google/auto/issues/560#issuecomment-352201816
Hi, @mkarneim Looks like issues: https://github.com/mkarneim/pojobuilder/blob/f77aab531b4b4268932716179b65f04e6ae18f36/src/main/java/net/karneim/pojobuilder/sourcegen/BuilderSourceGenerator.java#L84 https://github.com/mkarneim/pojobuilder/blob/f77aab531b4b4268932716179b65f04e6ae18f36/src/main/java/net/karneim/pojobuilder/sourcegen/BuilderSourceGenerator.java#L126 https://github.com/mkarneim/pojobuilder/blob/d6b46ffd957e4b71d35f1c37e2c1ab1915cb7f53/src/main/java/net/karneim/pojobuilder/sourcegen/ManualBuilderSourceGenerator.java#L38 https://github.com/mkarneim/pojobuilder/blob/d6b46ffd957e4b71d35f1c37e2c1ab1915cb7f53/src/main/java/net/karneim/pojobuilder/sourcegen/ManualBuilderSourceGenerator.java#L58
Can we delete dependency to Generator class?
I am currently working on this issue and planing to release a fix tomorrow or Wednesday.
Anyway, if you want to fix this yourself on your fork, removing the annotation from the source should do it. However, this would break the recommended conventions, saying that generated code should be marked accordingly.
Great, thank you.
@mkarneim if that annotation is removed. How is the code going to be generated then?
I guess this is a misunderstanding. ‘’‘@Generated‘‘‘ is not responsible for code generation.
So which version actually fixes the issue? I've moved to version 4.2.0 and I am still getting a
Fatal error compiling: java.lang.NoClassDefFoundError: javax/annotation/Generated: javax.annotation.Generated
``` error
What steps do I need to take to by pass this error?
Thank you
This is interesting. And yes, version 4.2.0 is the fixed one. Can you give me more details so that I can reproduce it, like build script, compiler version, source code?
Here is a little Java 9 Gradle project that shows that PojoBuilder 4.2.0 works with Java 9.
task wrapper(type: Wrapper) { gradleVersion = '4.5.1' }
apply plugin: 'java'
apply plugin: 'eclipse'
group = 'sample'
version = '1.0.0'
sourceCompatibility = 1.9
eclipse.jdt.sourceCompatibility = 1.9
repositories {
mavenCentral()
}
dependencies {
compile 'net.karneim:pojobuilder:4.2.0'
testCompile 'junit:junit:4.12'
}
tasks.withType(JavaCompile) { options.encoding = "UTF-8" }
# set the java home to java 1.9 if this isn't already default on your system
org.gradle.java.home=C:/Program Files/Java/jdk-9.0.1
package dummy;
import net.karneim.pojobuilder.GeneratePojoBuilder;
@GeneratePojoBuilder
public class Contact {
public String name;
public String email;
}
package dummy;
import org.junit.*;
import static org.junit.Assert.assertEquals;
public class ContactTest {
@Test
public void test() {
Contact c = new ContactBuilder().withEmail("mm").withName("xx").build();
assertEquals("c.name", "xx", c.name);
}
}
You can build this project from the command line with:
gradlew clean build
Hello. I am trying to use pojobuilder 4.1.0 with Java 9. Please help me with error. I used example https://github.com/mkarneim/pojobuilder#annotating-a-constructor
I am building maven on java 9.
Error: