Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-28408

Jenkins can't load extension ContextExtensionPoint if dependency is optional

      As in tutorial:
      https://github.com/jenkinsci/job-dsl-plugin/wiki/Extending-the-DSL

      extend:

      @Extension(optional = true)
      public class AquaPluginJobDslExtension extends ContextExtensionPoint {
      
          @DslExtensionMethod(context = StepContext.class)
          public Object aqua(Runnable closure) {
              AquaContext context = new AquaContext();
              executeInContext(closure, context);
      
              return new AquaPluginBuilder(
                      context.getPacks(),
                      context.getRunType(),
                      context.getLogLevel().getName(),
                      context.getTimeout(),
                      context.getUnits().name(),
                      context.getDelayPollSec()
              );
          }
      }
      

      with dependency:

      <dependency>
                  <groupId>org.jenkins-ci.plugins</groupId>
                  <artifactId>job-dsl</artifactId>
                  <version>1.34</version>
                  <optional>true</optional>
      </dependency>
      

      Then with job-dsl 34 installed do in jenkins script console:

      import javaposse.jobdsl.plugin.ContextExtensionPoint;
      
      Jenkins.instance.refreshExtensions();
      println(Jenkins.instance.getExtensionList(ContextExtensionPoint.class))
      

      prints "[]"

      With dependency <optional>false</optional>

      it prints:
      [com.example.dsl.AquaPluginJobDslExtension@2ee05de3]

      Okay,
      do the same with token macro plugin:

       <dependency>
                  <groupId>org.jenkins-ci.plugins</groupId>
                  <artifactId>token-macro</artifactId>
                  <version>1.10</version>
                  <optional>true</optional>
              </dependency>
      
      @Extension(optional = true)
      public class TokenMExt extends DataBoundTokenMacro {
          @Override
          public String evaluate(AbstractBuild<?, ?> abstractBuild, TaskListener taskListener, String s) throws MacroEvaluationException, IOException, InterruptedException {
              return null;
          }
      
          @Override
          public boolean acceptsMacroName(String s) {
              return false;
          }
      }
      

      in console:

      import org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro;
      
      println(Jenkins.getInstance().getExtensionList(DataBoundTokenMacro.class))
      

      prints:
      [..., org.jenkinsci.plugins.tokenmacro.impl.PropertyFromFileMacro@11786964, com.example.dsl.TokenMExt@13a9b76f]

          [JENKINS-28408] Jenkins can't load extension ContextExtensionPoint if dependency is optional

          Kirill Merkushev created issue -
          Kirill Merkushev made changes -
          Summary Original: Jenkins can't load extension if dependency is optional New: Jenkins can't load extension ContextExtensionPoint if dependency is optional

          Daniel Spilker added a comment - Hm, no clue. All I did was following the docs, see https://wiki.jenkins-ci.org/display/JENKINS/Dependencies+among+plugins#Dependenciesamongplugins-Optionaldependencies and https://wiki.jenkins-ci.org/display/JENKINS/Defining+a+new+extension+point .

          Does the manifest of your plugin list the job-dsl plugin as (optional) plugin dependency? Can you unzip the HPI and check META-INF/MANIFEST.MF? It should contain something like Plugin-Dependencies: job-dsl:1.34;resolution:=optional. Which version of the maven-hpi-plugin are you using?

          Daniel Spilker added a comment - Does the manifest of your plugin list the job-dsl plugin as (optional) plugin dependency? Can you unzip the HPI and check META-INF/MANIFEST.MF? It should contain something like Plugin-Dependencies: job-dsl:1.34;resolution:=optional . Which version of the maven-hpi-plugin are you using?

          I think the problem is that the Job DSL plugin POM has packaging type of jpi (see http://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/job-dsl/1.34/job-dsl-1.34.pom) as generated by the gradle-jpi-plugin. And the maven-hpi-plugin only considers the hpi packaging type as plugin dependency, see https://github.com/jenkinsci/maven-hpi-plugin/blob/maven-hpi-plugin-1.113/src/main/java/org/jenkinsci/maven/plugins/hpi/MavenArtifact.java#L64.

          Daniel Spilker added a comment - I think the problem is that the Job DSL plugin POM has packaging type of jpi (see http://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/job-dsl/1.34/job-dsl-1.34.pom ) as generated by the gradle-jpi-plugin. And the maven-hpi-plugin only considers the hpi packaging type as plugin dependency, see https://github.com/jenkinsci/maven-hpi-plugin/blob/maven-hpi-plugin-1.113/src/main/java/org/jenkinsci/maven/plugins/hpi/MavenArtifact.java#L64 .
          Daniel Spilker made changes -
          Component/s New: gradle-jpi-plugin [ 16321 ]
          Daniel Spilker made changes -
          Component/s New: core [ 15593 ]

          Daniel Spilker added a comment - Fix for the gradle-jpi-plugin: https://github.com/jenkinsci/gradle-jpi-plugin/pull/53

          Stefan Wolf added a comment -

          Shouldn't we fix the maven-hpi-plugin instead of the gradle jpi plugin?

          Stefan Wolf added a comment - Shouldn't we fix the maven-hpi-plugin instead of the gradle jpi plugin?

          I use maven-hpi-plugin:1.106 (same with latest 1.113)
          If i add token macro as optional dep, then in manifest i see

          Plugin-Dependencies: token-macro:1.10;resolution:=optional

          And if i add job-dsl-plugin as optional, no any tag

          Plugin-Dependencies

          in manifest

          Kirill Merkushev added a comment - I use maven-hpi-plugin:1.106 (same with latest 1.113) If i add token macro as optional dep, then in manifest i see Plugin-Dependencies: token-macro:1.10;resolution:=optional And if i add job-dsl-plugin as optional, no any tag Plugin-Dependencies in manifest

            daspilker Daniel Spilker
            lanwen Kirill Merkushev
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: