首页 文章

我怎样才能使用自己的parent.pom而不是“spring-boot-starter-parent”?

提问于
浏览
0

我是Spring,Spring boot和Spring boot starter的新手 .

对于我的不同应用程序,我使用自己的parent.pom来实现它们的共同点 . parent.pom包含版本号作为属性和依赖项,这些属性和属性使用属性作为版本号 .

当使用我的parent.pom maven时,我必须使用“spring-boot-starter-parent” .

我怎样才能使用自己的parent.pom而不是“spring-boot-starter-parent”?

与此同时,我改变了pom:

http://maven.apache.org/xsd/maven-4.0.0.xsd“> 4.0.0

<groupId>com.websystique.springboot</groupId>
<artifactId>SpringBootRestApiExample</artifactId>
<version>1.0.0</version>
<name>SpringBootRestApiExample</name>

<parent>
    <groupId>my</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../parent/pom.xml</relativePath>
</parent>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>   
    <!-- Add typical dependencies for a web application -->
    <!-- Adds Tomcat and Spring MVC, along others -->
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.0.1.RELEASE</version>
        </plugin>
    </plugins>
</build>

但是现在我收到了这个警告:

dependencies.dependency.scope' for org.springframework.boot:spring-boot-starter-parent:pom must be one of [provided, compile, runtime, test, system] but is 'import'. @ line 27, column 1

3 回答

  • 1

    您是否尝试过更新pom的setting.xml?

    <repository>
    			<id>central</id>
    			<url>https://repo.maven.apache.org/maven2</url>
    			<releases>
    				<enabled>true</enabled>
    			</releases>
    			<snapshots>
    				<enabled>true</enabled>
    			</snapshots>
    </repository>
    
  • -1

    也可以导入spring-boot-starter-parent pom . 因此,您可以使用自己的pom作为父级,并且可以使用spring boot pom中的依赖关系管理 .

    ...
    <dependencyManagement>
      <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.1.RELEASE</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>   
      </dependencies>
    </dependencyManagement>
    

    ...

  • 1

    您不必使用 spring-boot-starter-parent ,它只是具有广泛的 dependencyManagement 部分,可确保您在子项目中使用的所有Spring Boot依赖项具有相互兼容的版本 .

    我通常将 spring-boot-starter-parent 声明为 the parent POM of my parent POM . 这样,您可以获得两种选择中的最佳选择 .

相关问题