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

writeMavenPom / java.lang.ClassCastException when adding a new plugin

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • Jenkins 2.164.1
      Pipeline Utility Steps 2.3.0

      Trying to add a plugin to a pom, we are facing the following exception when writeMavenPom() is called:

       java.lang.ClassCastException: org.apache.maven.model.Plugin cannot be cast to org.apache.maven.model.Plugin
      	at org.apache.maven.model.io.xpp3.MavenXpp3Writer.writeBuild(MavenXpp3Writer.java:343)
      	at org.apache.maven.model.io.xpp3.MavenXpp3Writer.writeModel(MavenXpp3Writer.java:1134)
      	at org.apache.maven.model.io.xpp3.MavenXpp3Writer.write(MavenXpp3Writer.java:134)
      	at org.jenkinsci.plugins.pipeline.utility.steps.maven.WriteMavenPomStep$Execution.run(WriteMavenPomStep.java:160)
      	at org.jenkinsci.plugins.pipeline.utility.steps.maven.WriteMavenPomStep$Execution.run(WriteMavenPomStep.java:130)
      	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      	at java.lang.Thread.run(Thread.java:748)
      

      Minimal code that reproduces the problem:

      import org.apache.maven.model.Plugin
      
      writeFile file: 'pom.xml', text: '<project><modelVersion>4.0.0</modelVersion><build></build></project>'
      
      def myPom = readMavenPom()
      myPom.getBuild().getPlugins().add(new Plugin())
      writeMavenPom(myPom)
      

      This initial idea was to automatically add checkstyle version for maven-checkstyle-plugin to pom.xml files as recommended.
      So, from QA point of view, we can manage checkstyle version over all our java projects, and there is no need to change project specific settings which are still pom file.

      Many thanks for your help and this plugin!

            rsandell rsandell
            fr33ky fr33ky _
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: