Uploaded image for project: 'Maven Dependency Plugin'
  1. Maven Dependency Plugin
  2. MDEP-594

Dependency reported as "unused declared" when runtime-retention type annotation is used

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Resolved
    • Affects Version/s: 3.0.0
    • Fix Version/s: 3.1.0
    • Component/s: analyze
    • Labels:
      None
    • Environment:
      Apache Maven 3.5.0,
      Oracle Java version: 1.8.0_144

      Description

      In the attached example project, module "usage" uses annotation @Example:

      public interface Usage {
        @Example String getEmail(); 
      }
      

      which is defined in module "annotation" as:

      @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
      @Retention(RetentionPolicy.RUNTIME)
      public @interface Example {
      }
      

      Consequently, the pom.xml of module "usage" defines a compile-dependency to module "annotation" but the dependency:analyze-only goal incorrectly reports this as unused dependency:

      [main] [INFO] --- maven-dependency-plugin:3.0.0:analyze-only (analyze-dependencies) @ usage ---
      [main] [WARNING] Unused declared dependencies found:
      [main] [WARNING]    com.example:annotation:jar:1.0-SNAPSHOT:compile
      

      This false positive is only reported if

      • the annotation is meta-annotated with target TYPE_USE + TYPE_PARAMETER
      • and the source.version/target.version of the compiler plugin for module "usage" is 1.8

      There's no false positive if the @Target meta-annotation is removed or if compiler's source/target version is set to 1.7.

        Attachments

        1. example.tgz
          1 kB
          Andreas Hubold

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ahubold Andreas Hubold
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: