Sure, here’s the translation: Maven,继承pom模块

huangapple 未分类评论49阅读模式
英文:

Maven, Inherit pom module

问题

我正在编写一个项目,但在编译项目时遇到了问题。在我根据pom文件中显示的方式导入了必要的依赖后,我无法运行项目。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <artifactId>universeBySali-web</artifactId>
  <packaging>war</packaging>

   <parent>
    <groupId>org.springframework.boot</groupId>
   	 <artifactId>spring-boot-starter-parent</artifactId>
   		 <version>1.3.6.RELEASE</version>
 	 </parent>
 
	<properties>
  		<java.version>13.0.2</java.version>
 	</properties>
  
    <dependencies>
    	<dependency>
    		<groupId>com.vaadin</groupId>
    		<artifactId>vaadin-spring-boot-starter</artifactId>
    		<version>15.0.0</version>
    	</dependency>
    	<dependency>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-web</artifactId>
    	</dependency>
    	
    	<dependency>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-test</artifactId>
    	</dependency>
    	<dependency>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-data-jpa</artifactId>
    	</dependency>
    	<dependency>
    		<groupId>com.sali</groupId>
    		<artifactId>universeBySali-ui</artifactId>
    		<version>0.0.1-SNAPSHOT</version>
    	</dependency>
    </dependencies>
    
    <build>
  	<plugins>
  		<plugin>
  			<groupId>org.springframework.boot</groupId>
  			<artifactId>spring-boot-maven-plugin</artifactId>
  			<configuration>
  				<executable>true</executable>
  			</configuration>
  		</plugin>
  			
  		<plugin>
  			<groupId>org.apache.maven.plugins</groupId>
  			<artifactId>maven-war-plugin</artifactId>
  			<configuration>
  				<failOnMissingWebXml>false</failOnMissingWebXml>
  			</configuration>
 		</plugin>
  	</plugins>
  </build>
</project>

pom文件显示的错误如下:

项目构建错误:POM org.springframework.boot:universeBySali-web:1.3.6.RELEASE (C:\Users\User\Desktop\Materiale\Desktop\Java Projects\universeBySali\universeBySali-web\pom.xml) 的'parent.relativePath'指向 com.sali:universeBySali 而不是 org.springframework.boot:spring-boot-starter-parent,请验证您的项目结构

该pom文件具有如下所示的父pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.sali</groupId>
  <artifactId>universeBySali</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <modules>
  	<module>universeBySali-Model</module>
  	<module>universeBySali-repository</module>
  	<module>universeBySali-service</module>
  	<module>universeBySali-util</module>
  	<module>universeBySali-web</module>
  	<module>universeBySali-ui</module>
  </modules>
</project>

有人能告诉我我做错了什么吗?谢谢
英文:

I am writing a project but I encountered a problem compiling my project. After I imported the necessary dependencies, as shown on the pom file, I couldnt run the project.

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  
  &lt;artifactId&gt;universeBySali-web&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  
   &lt;parent&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
   	 &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
   		 &lt;version&gt;1.3.6.RELEASE&lt;/version&gt;
 	 &lt;/parent&gt;
 	 
 	&lt;properties&gt;
  		&lt;java.version&gt;13.0.2&lt;/java.version&gt;
 	 &lt;/properties&gt;
  
    &lt;dependencies&gt;
    	&lt;dependency&gt;
    		&lt;groupId&gt;com.vaadin&lt;/groupId&gt;
    		&lt;artifactId&gt;vaadin-spring-boot-starter&lt;/artifactId&gt;
    		&lt;version&gt;15.0.0&lt;/version&gt;
    	&lt;/dependency&gt;
    	&lt;dependency&gt;
    		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    		&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
    	&lt;/dependency&gt;
    	
    	&lt;dependency&gt;
    		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    		&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
    	&lt;/dependency&gt;
    	&lt;dependency&gt;
    		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    		&lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
    	&lt;/dependency&gt;
    	&lt;dependency&gt;
    		&lt;groupId&gt;com.sali&lt;/groupId&gt;
    		&lt;artifactId&gt;universeBySali-ui&lt;/artifactId&gt;
    		&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    	&lt;/dependency&gt;
    &lt;/dependencies&gt;
    
        &lt;build&gt;
  	&lt;plugins&gt;
  		&lt;plugin&gt;
  			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  			&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
  			&lt;configuration&gt;
  				&lt;executable&gt;true&lt;/executable&gt;
  			&lt;/configuration&gt;
  		&lt;/plugin&gt;
  			
  		&lt;plugin&gt;
  			&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  			&lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
  			&lt;configuration&gt;
  				&lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
  			&lt;/configuration&gt;
 		&lt;/plugin&gt;
  	&lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;

The error that it shows on the pom file is as follows:

Project build error: 'parent.relativePath' of POM org.springframework.boot:universeBySali-web:1.3.6.RELEASE (C:\Users\User\Desktop\Materiale\Desktop\Java Projects\universeBySali\universeBySali-web\pom.xml) points at com.sali:universeBySali instead of org.springframework.boot:spring-boot-starter-parent, please verify your project structure

This pom file has a parent pom as shown below:

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.sali&lt;/groupId&gt;
  &lt;artifactId&gt;universeBySali&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;pom&lt;/packaging&gt;
  &lt;modules&gt;
  	&lt;module&gt;universeBySali-Model&lt;/module&gt;
  	&lt;module&gt;universeBySali-repository&lt;/module&gt;
  	&lt;module&gt;universeBySali-service&lt;/module&gt;
  	&lt;module&gt;universeBySali-util&lt;/module&gt;
  	&lt;module&gt;universeBySali-web&lt;/module&gt;
  	&lt;module&gt;universeBySali-ui&lt;/module&gt;
  &lt;/modules&gt;
&lt;/project&gt;

Can somebody tell me what I am doing wrong?? Thanks

答案1

得分: 0

默认情况下,Maven假定父项目具有以下relativePath路径:../pom.xml
Maven将尝试匹配groupId/artifactId/version,如果失败则会发出警告并使用“外部”父项目。
为确保Maven不会在多模块中尝试解析父项目,您应该在父项目中添加<relativePath/>

英文:

By default Maven assumes the parent has the following relativePath: ../pom.xml.
Maven will try to match match the groupId/artifactId/version, if it doesn't succeed a warning is thrown and an "external" parent is used.
To ensure Maven won't try to solve the parent as part of your multimodule, you should add &lt;relativePath/&gt; to the parent.

huangapple
  • 本文由 发表于 2020年3月16日 04:07:31
  • 转载请务必保留本文链接:https://java.coder-hub.com/60697145.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定