Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

java - How to exclude a direct dependency of a Maven Plugin

I want to exclude a direct dependency of a Maven plugin and the approach described in this answer does not work (as indicated by this comment).

As a particular example:

<build>
    <plugins>
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.13.2</version>
            <!-- more config -->
            <dependencies>
                <dependency>
                    <groupId>org.jvnet.jaxb2.maven2</groupId>
                    <artifactId>maven-jaxb2-plugin</artifactId>
                    <version>0.13.2</version>
                    <exclusions>
                        <exclusion>
                            <groupId>javax.xml.bind</groupId>
                            <artifactId>jaxb-api</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

I still see javax.xml.bind:jaxb-api in the list of dependencies (with mvn ... -X). What am I doing wrong?

(In case someone has an idea for how to replace the dependency on that artifact with the JDK 9 equivalent for that API [as seems to happen on Java 8, where "JAXB API os loaded from the [jar:...jre/lib/rt.jar]"], I'm happy to open a new issue for that.)

Update

Running out of ideas and this being an experiment anyways, I excluded the dependency by editing the plugin's pom.xml in my local repository. Now mvn ... -X shows that there is also an indirect dependency (in this case by org.jvnet.jaxb2.maven2:maven-jaxb22-plugin) that I can successfully exclude with the mechanism above. Just using both excludes, from maven-jaxb2-plugin and maven-jaxb22-plugin, does not do the trick. This indicates that exclusion works in general but apparently not on a plugin's direct dependency.

(By the way, this indeed lead to "Java JAXB API is loaded from the [jrt:/java.xml.bind]", which was my goal.)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Up until now there hasn't been any reason to do this, but this seems like a valid one. Most clean solution I can think of is allowing to override the scope with "none" for plugin dependencies.

I've created MNG-6222 for it, not sure if we'll fix this for a Maven3, but it makes sense to do it at least for the next major.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...