Maven-plugin and creating a <bulid> element

plugins

(Paul Hicks) #1

I want to support both gradle wrapper and maven wrapper in a single project for my users’ benefit. I want to work only in gradle, but produce a pom.xml and mvnw script.

I’m trying to use the maven-plugin’s pom method to create a element like this:

task mavenWrapper {
  doLast {
    delete 'pom.xml', 'mvnw', 'mvnw.cmd'
      pom {
        project {
          // .. other stuff..
          build {
            // .. this causes error
          }
        }
      }
    }
  }

But I’m getting this error on the build block:

Execution failed for task ':mavenWrapper'.
> No such property: _SCRIPT_CLASS_NAME_ for class: org.apache.maven.model.Model

Right now I’m building the build block manually in the withXml method, but it’s ugly. The DSL looks like it should support this. I’m guessing that the build work is finding the task before the DSL verb, and that’s not what I want. How do I get build to be recognized as the DSL verb?

I’ve already asked this question on Stack Overflow.


(Stefan Oehme) #2

delegate.build should work.


(Paul Hicks) #3

Sorry about the massive delay!
Just tried delegate.build. No change :frowning: The relevant snippet is just this:

...
project {
  // ...
}
delegate.build {
  // ...
}
properties {
  // ...
}

(Dimitri KOPRIWA) #4

Hello @tenwit , I confirm this make the task fail on gradle 3.5 . Did you succeed or find a workaround ?


(Paul Hicks) #5

The initial workaround still works. It’s just massive (about 70% of the entire file, and that’s pretty big) and hard to maintain.

The workaround is to use withXml and DOM-manipulation methods.

pom {
  // DSL goes here, excluding build section
}.withXml {
       // Workaround for the missing build { ... } section above.
       asNode().appendNode('build').appendNode('plugins')
       // etc. etc.
}

The Stack Overflow question puts it in context.