Details
-
Type:
Bug
-
Status: Open (View Workflow)
-
Priority:
Major
-
Resolution: Unresolved
-
Component/s: pipeline-utility-steps-plugin
-
Labels:None
-
Environment:Jenkins 2.164.1
Pipeline Utility Steps 2.3.0
-
Similar Issues:
Description
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!
I have a similar problam;
My code as below ;
stage("StaticAnalysis"){
steps{
script
{ Plugin p= new Plugin(); p.setGroupId("org.apache.maven.plugins"); p.setArtifactId("maven-pmd-plugin"); p.setVersion("3.12.0"); def pom= readMavenPom file: '' pom.getBuild().getPlugins().add(p); writeMavenPom(pom); }The result of the executed pipeline as below
[Pipeline] End of Pipelinejava.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)