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

writeMavenPom throws class cast exception when creating a new pom file

    Details

    • Similar Issues:

      Description

      Creation of a pom file from a pipeline

      node ('master') {
          Model pom = new Model()
          pom.artifactId = 'my-test-project'
          pom.groupId = 'com.example.jenkins.test'
          pom.version = '1.1-SNAPSHOT'
          writeMavenPom(pom)
      }
      

      using writeMavenPom fails with:

      [Pipeline] End of Pipeline
      java.lang.ClassCastException: org.jenkinsci.plugins.pipeline.utility.steps.maven.WriteMavenPomStep.model expects class org.apache.maven.model.Model but received class org.apache.maven.model.Model
      

      However, reading and existing pom, making modifications and writing those to a file works like a charm.
      Test case for writeMavenPom (https://github.com/jenkinsci/pipeline-utility-steps-plugin/blob/master/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/maven/WriteMavenPomStepTest.java) passes, but it is using an older version of pipeline dependencies.

        Attachments

          Issue Links

            Activity

            Hide
            initialzero Marc Benstein added a comment - - edited

            Here's a workaround

            writeFile file: 'pom.xml', text: '<project><modelVersion>4.0.0</modelVersion></project>'
             def pom = readMavenPom()
             pom.artifactId = 'some.id'
             pom.groupId = 'org.something'
             pom.version = '1.0.0-SNAPSHOT'
             pom.packaging = 'zip'
            
            writeMavenPom model: pom
            
            Show
            initialzero Marc Benstein added a comment - - edited Here's a workaround writeFile file: 'pom.xml' , text: '<project><modelVersion>4.0.0</modelVersion></project>' def pom = readMavenPom() pom.artifactId =  'some.id' pom.groupId = 'org.something' pom.version =  '1.0.0-SNAPSHOT' pom.packaging = 'zip' writeMavenPom model: pom
            Hide
            janis_b Janis Balodis added a comment -

            The workaround works. Thank you.

            Show
            janis_b Janis Balodis added a comment - The workaround works. Thank you.

              People

              • Assignee:
                rsandell rsandell
                Reporter:
                janis_b Janis Balodis
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: