我有一个多模块maven项目,目录结构是分层的.有些模块依赖于其他模块.我已将依赖模块添加到项目POM的依赖项部分.但是,为了解决这些依赖关系,我需要导入父项目,然后选择Project Properties> Maven并选择"Enabled Modules".这是正常的吗?为什么项目不能解决工作区中的依赖项目?
谢谢,杰夫
我为几个不同的客户提供了几个ANT项目; 我对我的项目的目录结构如下所示:
L___standard_workspace
L___.hg
L___validation_commons-sub-proj <- JS Library/Module
| L___java
| | L___jar
| L___old_stuff
| L___src
| | L___css
| | L___js
| | L___validation_commons
| L___src-test
| L___js
L___v_file_attachment-sub-proj <- JS Library/Module
| L___java
| | L___jar
| L___src
| | L___css
| | L___js
| L___src-test
| L___js
L___z_business_logic-sub-proj <- JS Library/Module
| L___java
| | L___jar
| L___src
| L___css
| L___js
L____master-proj <- Master web-deployment module where js libraries are compiled to.
L___docs
L___java
| …Run Code Online (Sandbox Code Playgroud) 我们正在使用不同的架构层构建一个小型应用程序,例如域,接口,基础架构和应用程序.这遵循洋葱DDD模型.现在我想知道将应用程序拆分为多模块maven项目是否有任何好处.据我所知,现在似乎使事情变得比需要的更困难.整个应用程序将作为单个WAR文件部署到Tomcat容器中.
我无法找到一个好的,可扩展的解决方案的问题:
我有一个项目,可以提供给定工件的多种风格.这已被设置为多模块项目,目前有3个模块:
问题是我还有另外50个需要以相同方式设置的项目,即提供3种口味.
解决方案:
任何想法如何做得很好?还有其他选择吗?
谢谢,卢卡斯
编辑:
另一个选择是使用reactor扩展maven-reactor-plugin :inject-modules目标,它将从外部工件下载模块定义,并将其定义附加为普通模块.这将动态创建一个新模块.然后所有50个项目都可以使这个pom.xml成为他们的父项.
配置看起来像这样(草稿):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-reactor-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>inject</id>
<phase>initialize</phase>
<goals>
<goal>inject-modules</goal>
</goals>
<configuration>
<modules>
<module>
<artifactId>flavour1_module</artifactId>
<groupId>[ groupId ]</groupId>
<version>[ version ]</version>
</module>
<module>
<artifactId>flavour2_module</artifactId>
<groupId>[ groupId ]</groupId>
<version>[ version ]</version>
</module>
<module>
<artifactId>flavour3_module</artifactId>
<groupId>[ groupId ]</groupId>
<version>[ version ]</version>
</module>
</modules>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这样做会有意义吗?
更新: …
我有一个带Maven的多模块Spring项目.我正在使用Spring 3.2.3和注释配置.
我有以下布局:
parent
common (depends on parent)
webapp (depends on parent, common, module1, module2)
module1 (depends on parent)
module2 (depends on parent)
Run Code Online (Sandbox Code Playgroud)
我需要它common,module1并且module2可以指定自己的i18n属性(并webapp收集这些文件并以某种方式提供它们?!):
common: src/main/resources/i18n/messages_en.properties
module1: src/main/resources/i18n/messages_en.properties
module2: src/main/resources/i18n/messages_en.properties
Run Code Online (Sandbox Code Playgroud)
我试过用
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasename("classpath:/i18n/messages");
messageSource.setDefaultEncoding("UTF-8");
messageSource.setUseCodeAsDefaultMessage(true);
return messageSource;
}
Run Code Online (Sandbox Code Playgroud)
但是看起来Spring只会使用其中一个翻译文件,而是应该使用all.
另一种可能性是为每个模块指定一个唯一的属性文件名,但后来我不知道要设置的基本名称messageSource.setBasename(...).
谢谢你的帮助!
spring spring-mvc internationalization multi-module spring-3
问题
我有一个maven项目,其结构与下面的相似:(
为简化起见而简化)
--parent
|-- child A (inherits from parent)
|-- child B (inherits from parent)
|-- child B1 (inherits from B)
|-- child B2 (inherits from B)
|-- child B3 (inherits from B)
Run Code Online (Sandbox Code Playgroud)
仅仅孩子B1和B2必须使用包含一些额外构建内容的特定配置文件构建.结果,配置文件已在模块B中指定.
逻辑上,模块属于模块B,并且还继承了一些依赖项等(aggreagtion + inheritance).
(想象一下像B = Frontend,B1 = UI,B2 = Themes,B3 = Something)
题
编辑
编辑,因为问题被确定为重复:问题是相应问题中提到的解决方案不起作用.
如果我通过使用属性激活子配置文件,它也将被激活模块B(父级)和所有子级.
我只希望它对孩子B1和B2有效.
项目结构: 纯Kotlin作为多模块maven应用
kotlinspringboot(root-module)
API
集成的测试
问题: 我跑的时候
$ cd ./kotlingspringboot/integration-tests/
$ mvn test
Run Code Online (Sandbox Code Playgroud)
要么
$ cd ./kotlingspringboot/integration-tests/
$ mvn kotlin:test-compile
Run Code Online (Sandbox Code Playgroud)
我从api模块得到关于类的未解析引用的编译错误:
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.2.21:test-compile (test-compile) on project hello-integration-tests: Compilation failure: Compilation failure:
[ERROR] C:\workspace\kotlinspringboot\integration-tests\src\test\kotlin\org\ildar\hello\integration\HelloEndpointTests.kt:[6,18] Unresolved reference: SpringKotlinHelloWorldApplication
Run Code Online (Sandbox Code Playgroud)
注意:我之前运行过mvn clean install并验证.m2缓存包含有效的api模块jar.
api(子模块)pom.xml
....
<parent>
<artifactId>kotlin-spring-boot</artifactId>
<groupId>org.ildar</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hello-api</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
....
Run Code Online (Sandbox Code Playgroud)
集成测试(子模块)pom.xml
<parent>
<artifactId>kotlin-spring-boot</artifactId>
<groupId>org.ildar</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hello-integration-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals> <goal>compile</goal> </goals>
</execution> …Run Code Online (Sandbox Code Playgroud) 这是不是之间的区别的常见问题api和implementation,并希望将但从构建一个多模块项目的点更先进的和有趣的.
假设我在应用程序中有以下模块
librarybasefeature1feature2app现在模块之间的关系是:
base 包装 library
feature1并feature2使用(取决于)base
app拼feature1和feature2
这个多模块结构中的所有内容都应该能够使用Gradle的implementation依赖项工作,并且不需要在api任何地方使用该子句.
现在,让我们说feature1需要访问base包含在其中的实现细节library.
为了使library提供给feature1我们有两个选择,据我可以告诉:
更改implementation为api在base泄漏依赖于依赖模块base
library作为implementation依赖项添加,feature1而不会base泄漏依赖性library
当然,为了解决这个问题,这个例子已经被简化了,但是你明白了这可能会成为一个具有4或5级依赖关系的大量模块的配置地狱.
我们可以创建一个base-feature中间模块,它可以包装base并提供另一级抽象,以便feature1在不泄漏的情况下使用library,但让我们将该解决方案置于此问题的范围之外,以专注于依赖项的设置.
我在上述选项中检测到的一些权衡:
选项1)专业人士
build.gradle的文件,因为不需要重复implementation条款api …我需要帮助,我正在 go 工作区中工作,工作区中有多个使用通用功能的项目。因此,我所做的是制作一个单独的模块,其中包含其他模块使用的所有常用功能。
\n当我们使用 go 工作区时,所有模块都可以共享它们的代码。
\n文件结构如下:
\nWorkspace\n\xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Project1\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main.go\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 docker-compose.yml\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Dockerfile\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 go.mod\n\xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Project2\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main.go\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 docker-compose.yml\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Dockerfile\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 go.mod\n\xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Common\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 functionality.go\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 go.mod\n\xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 go.work\nRun Code Online (Sandbox Code Playgroud)\ncommon/functionality.goProject1 和 Project2通过将它们导入到项目中来使用其中的功能。
当我运行docker-compose up -d命令时project1,它说您在项目中导入的公共模块不在 GOROOT 中。\n因为这里 docker 仅容器化目录中的文件Project1
我怎样才能分别dockerizeProject1和Project2???
原谅我.我是Maven的菜鸟.
这是我的maven项目目录:
project/
pom.xml
moduleA/
moduleB/
sub-moduleA/
sub-moduleB/
sub-moduleC/
moduleC/
Run Code Online (Sandbox Code Playgroud)
当然,在每个模块和子模块中,它们都有自己的模块和子模块pom.xml.此外,在此示例中moduleB取决于moduleA并moduleA取决于moduleC.我知道在maven中它经历了多个阶段,但是它每次只需要一个阶段,或者每个阶段一个.眼下,只有三个阶段,我关心的是compile,package和install.
例如:
是否在订单1中执行此操作:
compile moduleC
compile moduleA
compile moduleB
package moduleC
package moduleA
package moduleB
install moduleC
install moduleA
install moduleB
Run Code Online (Sandbox Code Playgroud)
或者它是在第2顺序中执行的:
compile moduleC
package moduleC
install moduleC
compile moduleA
package moduleA
install moduleA
compile moduleB
package moduleB
install moduleB
Run Code Online (Sandbox Code Playgroud)
或者它是以完全不同的顺序进行的,还是我完全脱离了对maven的理解?
我正在运行Maven 2.2.1.谢谢!