From 72561d742884e857bc11cca290be26d9d04ec937 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 29 Nov 2017 04:05:27 +0100 Subject: javax.annotation.Generated will no longer be applied by default (Oracle broke it with JDK9). --- doc/changelog.markdown | 1 + src/core/lombok/ConfigurationKeys.java | 10 +++++++--- src/core/lombok/core/handlers/HandlerUtil.java | 2 +- website/templates/features/configuration.html | 6 ++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/doc/changelog.markdown b/doc/changelog.markdown index a3750112..6a5a7da5 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -6,6 +6,7 @@ Lombok Changelog * PLATFORM: Possible support for jdk9 in the new IntelliJ, Netbeans and for Gradle. * DEVELOPMENT: Compiling lombok on JDK1.9 is now possible. * BUGFIX: The generated hashCode would break the contract if `callSuper=true,of={}`. [Issue #1505](https://github.com/rzwitserloot/lombok/issues/1505) +* BREAKING CHANGE: _lombok config_ key `lombok.addJavaxGeneratedAnnotation` now defaults to `false` instead of true. Oracle broke this annotation with the release of JDK9, neccessitating this breaking change. ### v1.16.18 (July 3rd, 2017) * PLATFORM: JDK9 support much improved since v1.16.6; [Issue #985](https://github.com/rzwitserloot/lombok/issues/985) diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java index 90621027..3e049b42 100644 --- a/src/core/lombok/ConfigurationKeys.java +++ b/src/core/lombok/ConfigurationKeys.java @@ -41,19 +41,23 @@ public class ConfigurationKeys { /** * lombok configuration: {@code lombok.addGeneratedAnnotation} = {@code true} | {@code false}. * - * If unset or {@code true}, lombok generates {@code @javax.annotation.Generated("lombok")} on all fields, methods, and types that are generated, unless {@code lombok.addJavaxGeneratedAnnotation} is set. + * If {@code true}, lombok generates {@code @javax.annotation.Generated("lombok")} on all fields, methods, and types that are generated, unless {@code lombok.addJavaxGeneratedAnnotation} is set. + *
+ * BREAKING CHANGE: Starting with lombok v2.0.0, defaults to {@code false} instead of {@code true}, as this annotation is broken in JDK9. * * @see ConfigurationKeys#ADD_JAVAX_GENERATED_ANNOTATIONS * @see ConfigurationKeys#ADD_LOMBOK_GENERATED_ANNOTATIONS * @deprecated Since version 1.16.14, use {@link #ADD_JAVAX_GENERATED_ANNOTATIONS} instead. */ @Deprecated - public static final ConfigurationKey ADD_GENERATED_ANNOTATIONS = new ConfigurationKey("lombok.addGeneratedAnnotation", "Generate @javax.annotation.Generated on all generated code (default: true). Deprecated, use 'lombok.addJavaxGeneratedAnnotation' instead.") {}; + public static final ConfigurationKey ADD_GENERATED_ANNOTATIONS = new ConfigurationKey("lombok.addGeneratedAnnotation", "Generate @javax.annotation.Generated on all generated code (default: false). Deprecated, use 'lombok.addJavaxGeneratedAnnotation' instead.") {}; /** * lombok configuration: {@code lombok.addJavaxGeneratedAnnotation} = {@code true} | {@code false}. * - * If unset or {@code true}, lombok generates {@code @javax.annotation.Generated("lombok")} on all fields, methods, and types that are generated, unless {@code lombok.addGeneratedAnnotation} is set to {@code false}. + * If {@code true}, lombok generates {@code @javax.annotation.Generated("lombok")} on all fields, methods, and types that are generated. + *
+ * BREAKING CHANGE: Starting with lombok v2.0.0, defaults to {@code false} instead of {@code true}, as this annotation is broken in JDK9. */ public static final ConfigurationKey ADD_JAVAX_GENERATED_ANNOTATIONS = new ConfigurationKey("lombok.addJavaxGeneratedAnnotation", "Generate @javax.annotation.Generated on all generated code (default: follow lombok.addGeneratedAnnotation).") {}; diff --git a/src/core/lombok/core/handlers/HandlerUtil.java b/src/core/lombok/core/handlers/HandlerUtil.java index 6c3a0b79..f4705e5b 100644 --- a/src/core/lombok/core/handlers/HandlerUtil.java +++ b/src/core/lombok/core/handlers/HandlerUtil.java @@ -113,7 +113,7 @@ public class HandlerUtil { public static boolean shouldAddGenerated(LombokNode node) { Boolean add = node.getAst().readConfiguration(ConfigurationKeys.ADD_JAVAX_GENERATED_ANNOTATIONS); if (add != null) return add; - return !Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_GENERATED_ANNOTATIONS)); + return Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_GENERATED_ANNOTATIONS)); } public static void handleExperimentalFlagUsage(LombokNode node, ConfigurationKey key, String featureName) { diff --git a/website/templates/features/configuration.html b/website/templates/features/configuration.html index 0491d832..4f861287 100644 --- a/website/templates/features/configuration.html +++ b/website/templates/features/configuration.html @@ -79,10 +79,12 @@ can be included. We suggest you put this in the root of your workspace directory.

- Lombok normally adds @javax.annotation.Generated annotations to all generated nodes where possible. You can stop this with: + Lombok can add @javax.annotation.Generated annotations to all generated nodes where possible. You can enable this with:

- lombok.addJavaxGeneratedAnnotation = false + lombok.addJavaxGeneratedAnnotation = true
+ We advise against this; JDK9 breaks this annotation, and it's unlikely to ever get fixed.
+ NB: Until Lombok v2.0.0, this setting defaulted to true.

Lombok can be configured to add @lombok.Generated annotations to all generated nodes where possible; useful for JaCoCo (which has built in support), or other style checkers and code coverage tools: -- cgit