mavenyamlmaven-enforcer-plugin

Configuring Maven with YAML - maven-enforcer-plugin to be specific - not working


My Maven POM is YAML (thanks to io.takari.polyglot) and I am having a hard time writing the config in YAML because the example has values, but I believe I should configure the maven-enforcer-plugin's banTransitiveDependencies rule to take no includes or excludes.

Here's my attempt so far:

modelVersion: 4.0.0
artifactId: my-app
groupId: com.adam.stuff
version: 3.3.1
packaging: jar
properties:
    spring.boot.version: 1.5.10.RELEASE
    spring.core.version: 4.3.14.RELEASE
dependencies:
  - artifactId: spring-boot-dependencies
    groupId: org.springframework.boot
    version: ${spring.boot.version}
    type: pom
  - artifactId: spring-boot-starter-web
    groupId: org.springframework.boot
    version: ${spring.boot.version}
  - artifactId: spring-boot-starter-test
    groupId: org.springframework.boot
    version: ${spring.boot.version}
  - artifactId: spring-context
    groupId: org.springframework
    version: ${spring.core.version}
  - artifactId: spring-web
    groupId: org.springframework
    version: ${spring.core.version}
build:
    plugins:
      - artifactId: maven-enforcer-plugin
        groupId: org.apache.maven.plugins
        version: 3.0.0-M1
        executions:
          - id: enforce-ban-transitive-deps
            goals: [enforce]
            configuration:
                rules: 
                    banTransitiveDependencies: 
                        comment: "Don't be a dummy"
      - artifactId: spring-boot-maven-plugin
        groupId: org.springframework.boot
        version: ${spring.boot.version}
        executions:
          - goals: [repackage]
        configuration:
            fork: true
            executable: true

but the plugin complains:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M1:enforce (enforce-ban-transitive-deps) on project my-app: Unable to parse configuration of mojo org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M1:enforce for parameter rule: Cannot create instance of interface org.apache.maven.enforcer.rule.api.EnforcerRule: org.apache.maven.enforcer.rule.api.EnforcerRule.() -> [Help 1]

Here's the doc: https://maven.apache.org/enforcer/enforcer-rules/banTransitiveDependencies.html

and following that example would include and exclude stuff, which I don't want to do at this point - because I want to set it up to play with, once I've figured out the configuration!

I've also tried putting their XML through https://www.site24x7.com/tools/xml-to-yaml.html but it's still giving the same error.

If you want to experiment with pom.yml then create a dir and file called .mvn/extensions.xml and put it in the root of your project (next to the pom.xml) and have go:

<?xml version="1.0" encoding="UTF-8"?>
<extensions>
    <extension>
        <groupId>io.takari.polyglot</groupId>
        <artifactId>polyglot-yaml</artifactId>
        <version>0.2.1</version>
    </extension>
</extensions>

Solution

  • According to the rule Ban Transitive Dependencies' doc it's:

                        banTransitiveDependencies:
                            message: ...
    

    rather than:

                        banTransitiveDependencies:
                            comment: ...
    

    The following parameters are supported by this rule:

    • ...
    • ...
    • message - an optional message to the user if the rule fails. Will replace generated report message.