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

writeMavenPom throws class cast exception when creating a new pom file

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • Jenkins 2.36, Pipeline 2.4, Pipeline Utility Steps 1.2.1
      Oracle Java 1.8.0_40

      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.

          [JENKINS-40432] writeMavenPom throws class cast exception when creating a new pom file

          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
          

          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

          Janis Balodis added a comment -

          The workaround works. Thank you.

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

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

              Created:
              Updated:
              Resolved: