java - Maven:如何获取配置文件以从父 pom 继承 dependencyManagement 标记?

标签 java maven maven-3 wsgen

我运行 wsgen在它自己的配置文件中,因为我不希望它在我每次构建产品时都运行。但是我在运行它时收到有关缺少版本的错误:

$ mvn package -P wsgen [INFO] Scanning for projects... [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project project-ejb:2.3.15-SNAPSHOT (C:\Projects\MyProject\pom.xml) has 1 error [ERROR]
'build.plugins.plugin[org.jvnet.jax-ws-commons:jaxws-maven-plugin].dependencies.dependency.version' for org.glassfish:javax.javaee:jar is missing. @ line 167, column 41 [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException

这是子 pom 的片段(带有配置文件的 pom):

<packaging>ejb</packaging>
<parent>
    <artifactId>MyProject</artifactId>
    <groupId>project</groupId>
    <version>2.3.15-SNAPSHOT</version>
</parent>
<profiles>
    <profile>
        <id>wsgen</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jax-ws-commons</groupId>
                        <artifactId>jaxws-maven-plugin</artifactId>
                        <version>2.1</version>
                        <executions>
...
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.glassfish</groupId>
                        <artifactId>javax.javaee</artifactId>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</profile>

但是,在父 pom 中,我在 dependencyManagement 标签下定义了这个依赖及其版本。

我认为发生的事情是配置文件没有继承父级的 dependencyManagement 标记,因此它认为依赖项缺少版本号。有没有办法让配置文件从父级继承?

最佳答案

dependencyManagement 应用于 pom 和子 poms 中的dependencies。它不适用于 plugins 中的 dependencies(至少,这是我在几个插件中注意到的,比如 maven-dependency-plugin)。

一个可能的解决方案是在您的父 pom 中定义一个属性 (javax.javaee.version) 并在您的 dependencyManagement 和您的 jaxws-maven 中使用它-插件插件

关于java - Maven:如何获取配置文件以从父 pom 继承 dependencyManagement 标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14222413/

相关文章:

java - 如何使用 Spring Security 的新 PasswordEncoder

Java iText 第 X 页,共 Y 页

java - “找不到符号”或“无法解析符号”错误是什么意思?

java - maven:从 JDK 中排除 jar

java - Eclipse 2018-09 不会编译 Java 11 源代码;认为低于1.7

java - Maven 导致互联网连接崩溃

使用jdk12构建语言级别9 javadoc时javadoc失败

java - hibernate join fetch和二级缓存

java - Netbeans "default config"用于 Maven 项目

scala - 动态maven artifactId