Is there a Maven “compiler-only” scope for dependency artifacts

If a dependency is only used for building, such as an annotation processor, it should be a maven <plugin>, or <dependency> thereof.

Otherwise, if it is in the compilation classpath, it will be necessary for linking the generated class file at runtime. Then, there are two cases:

  1. It is always necessary to load that class
    1. the class should be shipped as part of the application: <scope>compile</scope>
    2. the class should be provided by the runtime environment: <scope>provided</scope>
  2. It is sometimes necessary (because that class will be loaded only under particular circumstances): <optional>true</optional>

The only option not covered is compiling a Java program, and never running it in a JVM. This is a really obscure use case, and I can’t fault the designers of maven for not including a scope just to express this distinction – particularly since it is irrelevant to Maven’s core responsibility (building the software).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)