简体   繁体   English

'dependencies.dependency.version' 缺少错误,但版本在父级中管理

[英]'dependencies.dependency.version' is missing error, but version is managed in parent

I have a maven project that contains several modules.我有一个包含多个模块的 Maven 项目。 In Eclipse (Juno, with m2e) it seems to compile fine.在 Eclipse(Juno,带有 m2e)中,它似乎编译得很好。 But when I do a maven install on one of the modules, the build fails immediately.但是当我在其中一个模块上进行 maven 安装时,构建会立即失败。

Parent pom:父pom:

  <groupId>com.sw.system4</groupId>
  <artifactId>system4-parent</artifactId>
  <version>${system4.version}</version>
  <packaging>pom</packaging>
  <name>System 4 Parent Project</name>
  <modules>
    <module>system4-data</module>
     ...others...
  </modules>
  <properties>
    <system4.version>0.0.1-SNAPSHOT</system4.version>
    <spring.version>3.2.3.RELEASE</spring.version>
    ... others...
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
        <scope>runtime</scope>
      </dependency>
    ... lots of others ...
    </dependencies>
  </dependencyManagement>

Child pom:儿童绒球:

  <parent>
    <groupId>com.sw.system4</groupId>
    <artifactId>system4-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>system4-data</artifactId>
  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <scope>runtime</scope>
    </dependency>
    ... lots of others...
  </dependencies>

When I build, I get the following output:当我构建时,我得到以下输出:

[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project com.sw.system4:system4-data:0.0.1-SNAPSHOT (C:\work\eclips
e_workspaces\systemiv\system4-parent\system4-data\pom.xml) has 8 errors

[ERROR]     'dependencies.dependency.version' for org.springframework:spring-cor
e:jar is missing. @ line 16, column 16

... others omitted for clarity ...

I dont understand why it doesn't even attempt to compile.我不明白为什么它甚至不尝试编译。 Ive tried removing the runtime scope from parent and child, and it makes no difference.我已经尝试从父级和子级中删除运行时范围,这没有任何区别。 Please help!请帮忙!

如果有人在这里遇到与我相同的问题,我的问题是我缺少从子 pom.xml 复制的依赖项周围的<dependencyManagement>标记。

A couple things I think you could try:我认为您可以尝试几件事:

  1. Put the literal value of the version in the child pom将版本的字面值放在pom 中

    <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.2.3.RELEASE</version> <scope>runtime</scope> </dependency>
  2. Clear your .m2 cache normally located C:\Users\user.m2\repository.清除通常位于 C:\Users\user.m2\repository 的 .m2 缓存。 I would say I do this pretty frequently when I'm working in maven.当我在 Maven 中工作时,我会说我经常这样做。 Especially before committing so that I can be more confident CI will run.尤其是在提交之前,这样我可以更有信心 CI 会运行。 You don't have to nuke the folder every time, sometimes just your project packages and the .cache folder are enough.您不必每次都对文件夹进行核对,有时只需您的项目包和 .cache 文件夹就足够了。

  3. Add a relativePath tag to your parent pom declaration将 relativePath 标记添加到您的父 pom 声明

    <parent> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1</version> <relativePath>../parent/pom.xml</relativePath> </parent>

It looks like you have 8 total errors in your poms.看起来你的 pom 中有 8 个错误。 I would try to get some basic compilation running before adding the parent pom and properties.在添加父 pom 和属性之前,我会尝试运行一些基本的编译。

Right, after a lot of hair tearing I have a compiling system.对,经过大量的头发撕裂后,我有了一个编译系统。

Cleaning the .m2 cache was one thing that helped (thanks to Brian)清理 .m2 缓存是一件有帮助的事情(感谢 Brian)

One of the mistakes I had made was to put 2 versions of each dependency in the parent pom dependencyManagement section - one with <scope>runtime</scope> and one without - this was to try and make eclipse happy (ie not show up rogue compile errors) as well as being able to run on the command line.我犯的一个错误是将每个依赖项的 2 个版本放在父 pom dependencyManagement 部分中 - 一个带有<scope>runtime</scope>一个没有 - 这是为了尝试让 eclipse 快乐(即不显示流氓编译错误)以及能够在命令行上运行。 This was just complicating matters, so I removed the runtime ones.这只是使事情复杂化,所以我删除了运行时的。

Explicitly setting the version of the parent seemed to work also (it's a shame that maven doesn't have more wide-ranging support for using properties like this!)显式设置父级的版本似乎也有效(遗憾的是,maven 没有更广泛的支持使用这样的属性!)

  <parent>
    <groupId>com.sw.system4</groupId>
    <artifactId>system4-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>

I was then getting weird 'failed to collect dependencies for' errors in the child module for all the dependencies, saying it couldn't locate the parent - even though it was set up the same as other modules which did compile.然后我对所有依赖项的子模块中的错误“无法收集依赖项”感到奇怪,说它无法找到父模块 - 即使它的设置与其他编译的模块相同。

I finally solved things by compiling from the parent pom instead of trying to compile each module individually.我终于通过从父 pom 编译而不是尝试单独编译每个模块来解决问题。 This told me of an error with a relatively simple fix in a different module, which strangely then made it all compile.这告诉我一个错误,在不同的模块中进行了相对简单的修复,然后奇怪地使它全部编译。

In other words, if you get maven errors relating to child module A, it may actually be a problem with unrelated child module Z, so look there.换句话说,如果您遇到与子模块 A 相关的 maven 错误,则实际上可能是不相关的子模块 Z 的问题,所以请看那里。 (and delete your cache) (并删除您的缓存)

In theory, maven does not allow to use a property to set a parent version.理论上,maven 不允许使用属性来设置父版本。

In your case, maven can simply not figure out that the 0.0.1-SNAPSHOT version of your parent pom is the one that is currently in your project, and so it tries to find it in your local repo.在您的情况下,maven 根本无法确定您的父 pom 的 0.0.1-SNAPSHOT 版本是您项目中当前的版本,因此它会尝试在您的本地存储库中找到它。 It probably finds one since it is a snapshot, but it is an old version that probably not contains your Dependency Management section.它可能会找到一个,因为它是一个快照,但它是一个旧版本,可能不包含您的依赖管理部分。

There is a workaround though :不过有一个解决方法:

Simply change the parent section in the child pom with this :只需使用以下命令更改子 pom 中的父部分:

<parent>
    <groupId>com.sw.system4</groupId>
    <artifactId>system4-parent</artifactId>
    <version>${system4.version}</version>
    <relativePath>../pom.xml</relativePath>  <!-- this must match your parent pom location -->
</parent>

I had the same error, I forgot to add the child dependencies in the <dependencyManagement> .我有同样的错误,我忘了在<dependencyManagement>中添加子依赖项。 For example in the parent pom:例如在父 pom 中:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.sw.system4</groupId>
            <artifactId>system4-data</artifactId><!-- child artifact id -->
            <version>${project.version}</version>
        <dependency>

        <!-- add all third party libraries ... -->

    </dependencies>
<dependencyManagement>

For those using the org.codehaus.mojo:flatten-maven-plugin : Be sure to set a flattenMode which keeps the dependencyManagement if you still want to import the pom (eg resolveCiFriendliesOnly ).对于那些使用org.codehaus.mojo:flatten-maven-plugin :如果您仍想导入 pom(例如resolveCiFriendliesOnly ),请务必设置一个flattenMode以保留dependencyManagement Otherwise, the plugin will remove the dependencyManagement section.否则,插件将删除dependencyManagement部分。

确保子项目/父/版本节点中的值与其父项目/版本值匹配

在做子模块之前,您必须先构建父模块。

刚刚起作用的是删除 .m2 文件夹中的 settings.xml:该文件告诉项目寻找不存在的 spring mvc 和 web 版本。

我遇到了同样的问题,我重命名了“.m2”上的“repository”文件夹(类似于repositoryBkp,名称并不重要,以防万一出现问题)并创建一个新的“repository”文件夹,然后我重新运行maven和所有项目编译成功

In my case I had the same dependency listed twice in the same pom.xml.就我而言,我在同一个 pom.xml 中列出了两次相同的依赖项。 Make sure it's only used once.确保它只使用一次。

对我来说,与我的dependencyManagement中的分类器相关的问题我有项目的依赖项(和“版本”关闭诅咒)我从dependencyManagement中删除了它解决了这个问题

If you are using modules and need lombok for child module you need to explicitly declare version as well like :如果您正在使用模块并且需要 lombok 作为子模块,则需要显式声明版本,例如:

<dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <optional>true</optional>
        </dependency>
    </dependencies>

It helped in my case.它对我的情况有所帮助。

In my case I was putting tomcat decency then I got the error and this what I used.在我的情况下,我把 tomcat 体面,然后我得到了错误,这就是我使用的。

<dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-core</artifactId>
            <version>9.0.44</version>
        </dependency>

Most probably your spring-framework-bom might not be existing.很可能您的 spring-framework-bom 可能不存在。 Recheck for the version if it has ".RELEASE" at the end.如果最后有“.RELEASE”,请重新检查版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 dependencies.dependency.version'缺少错误 - dependencies.dependency.version' is missing error 由于依赖关系而无法编译Maven项目。 - Not able to compile Maven project due to dependencies.dependency.version is missing 依赖版本缺失 - io.vertx:vertx-stack-depchain:jar 的“dependencies.dependency.version”缺失 - Dependency Version is missing - 'dependencies.dependency.version' for io.vertx:vertx-stack-depchain:jar is missing 删除dependencies.dependency.version错误 - removing dependencies.dependency.version errors 项目构建错误:&#39;dependencies.dependency.version&#39; for org.springframework.cloud:spring-cloud-starter-sleuth-zipkin:jar is missing - Project build error: 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-starter-sleuth-zipkin:jar is missing Spring 引导生成器错误:org.springframework.cloud:spring-cloud-starter-netflix-hystrix:jar 的“dependencies.dependency.version”缺失 - Spring boot builder error: 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-starter-netflix-hystrix:jar is missing org.glassfish.jersey.containers:jersey-container-grizzly2-http:jar的&#39;dependencies.dependency.version&#39;已丢失 - 'dependencies.dependency.version' for org.glassfish.jersey.containers:jersey-container-grizzly2-http:jar is missing org.slf4j的&#39;dependencies.dependency.version&#39;:缺少slf4j-jcl:jar - 'dependencies.dependency.version' for org.slf4j:slf4j-jcl:jar is missing maven 在执行无服务器部署到 aws 时出现构建错误(com.amazonaws:aws-lambda-java-events:Z68995FCBF432492D15484D04A9D2AC4 的“dependencies.dependency.version”缺失) - maven build error when doing serverless deploy to aws ('dependencies.dependency.version' for com.amazonaws:aws-lambda-java-events:jar is missing) Java Spring Boot issue 'dependencies.dependency.version' for org.hibernate:hibernate-validator:jar is missing. @ 第 57 行,第 21 列 - Java Spring Boot issue 'dependencies.dependency.version' for org.hibernate:hibernate-validator:jar is missing. @ line 57, column 21
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM