Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8234683

allow discoverable javac plugins to be invoked by default



    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 14
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Compatibility Kind:
    • Compatibility Risk:
    • Compatibility Risk Description:
      The feature is opt-in and will not affect existing plugins, except in the very rare case of a plugin that already defines an incompatible version of the new method.
    • Interface Kind:
      Java API
    • Scope:



      Allow a javac plugin to be invoked by default if it is not otherwise invoked with command-line arguments.


      Currently, javac plugins must be invoked explicitly from the command line, which may be inconvenient or impractical when javac is being invoked from higher level build tools such as Maven or Ant. In this context, "command line" includes both invocation from binary executables such as bin/javac or bin/javac.exe that launch a new JVM, and invocation by APIs that take an array or list of string-valued options that are similar to the arguments passed to a binary executable. This includes API such as:


      It is already the case that plugins can be linked into an image, using jlink, so that there is no need to specify any path options to locate the plugin. Allowing plugins to be started automatically would also eliminate the need to use a -Xplugin option on the command line.

      The proposed behavior should be "opt-in", so as not to affect any existing plugins. The behavior can be achieved by adding a new method boolean autoStart() to the Plugin interface, with a default implementation of return false;. The behavior is defined so that it can be overridden by an explicit invocation on the command line; this could be used to "opt-out" in those situations where the autostart behavior is not desired.

      The ability to start plugins by default is similar to the way that javac will automatically run annotation processors found by the default discovery process for annotation processors.


      The following method is added to com.sun.tools.javac.Plugin:

      @@ -62,4 +62,20 @@
            * @param args Arguments, if any, for the plug-in
           void init(JavacTask task, String... args);
      +    /**
      +     * Returns whether or not this plugin should be automatically started,
      +     * even if not explicitly specified in the command-line options.
      +     *
      +     * <p>This method will be called by javac for all plugins located by the
      +     * service loader. If the method returns {@code true}, the plugin will be
      +     * {@link #init(JavacTask,String[]) initialized} with an empty array of
      +     * string arguments if it is not otherwise initialized due to an explicit
      +     * command-line option.
      +     *
      +     * @return whether or not this plugin should be automatically started
      +     */
      +    default boolean autoStart() {
      +        return false;
      +    }


          Issue Links



              jjg Jonathan Gibbons
              jjg Jonathan Gibbons
              Reviewed By:
              Jan Lahoda, Maurizio Cimadamore
              0 Vote for this issue
              3 Start watching this issue