简体   繁体   English

多模块 Spring 项目与 Maven

[英]Multimodule Spring project with Maven

I am trying to build an app with multimodule architecture, where I have the following modules:我正在尝试构建一个具有多模块架构的应用程序,其中有以下模块:

  • app (with the controllers)应用程序(带有控制器)
  • persistence (where I keep all entities and repos)持久性(我保留所有实体和存储库)
  • domain (pure Java-module)域(纯 Java 模块)
  • a parent module that combines all these modules, but it has no code, only the pom-file and properties.一个结合了所有这些模块的父模块,但它没有代码,只有 pom 文件和属性。

How do I organize the project in order to have shared app-properties in the parent-module?如何组织项目以便在父模块中共享应用程序属性? And should the persistency module have spring-build plugin?持久性模块应该有spring-build插件吗? Cause at the moment no module sees the properties of the parent.因为目前没有模块看到父级的属性。

Technically it is possible to force pom -module to package artifacts , in your case that would be something like:从技术上讲,可以将pom -module 强制为 package artifacts ,在您的情况下,类似于:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>resources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <configuration>
                        <classifier>configs</classifier>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

However in that case child modules inherit build configuration from parent, so you will need to disable configuration of maven-jar-plugin in child modules.但是在这种情况下,子模块从父模块继承构建配置,因此您需要在子模块中禁用maven-jar-plugin的配置。 It is better to create sibling module rather than solving maven puzzles.最好创建兄弟模块而不是解决 maven 难题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM