我刚刚开始使用Maven构建应用程序.我的一种方法是构建一个多模块Web应用程序.使用Eclipse可以很容易地构建这种类型的应用程序.到目前为止一切正常.我失败的地方是部署.我使用Wildfly作为我的应用程序服务器,并且表示层的部署运行良好.但是,当我想从父项目部署时,我得到以下消息:
Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:1.0.1.Final:deploy (default-cli) on project build: Error executing FORCE_DEPLOY: C:\Users\*****\Desktop\workspace\mvnexbook-examples-1.0\ch-multi\target\parent-0.8-SNAPSHOT.maven-project (No such file or directory)
Run Code Online (Sandbox Code Playgroud)
这非常令人困惑.部署是否不是从.m2/repository文件夹中以前安装的文件进行的?我的父文件夹中是否需要目标目录?
我的父pom文件
<?xml version="1.0" encoding="UTF-8"?>
<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
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<version>0.8-SNAPSHOT</version>
</parent>
<artifactId>simple-webapp</artifactId>
<packaging>war</packaging>
<name>Multi Chapter Simple Web Application Project</name>
<dependencies>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.4_spec</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-weather</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<finalName>simple-webapp</finalName>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
编辑:我刚用码头试过.工作良好.为什么它不与Wildfly合作?
EDIT2:我正在使用sonatype书中的简单父项目示例
今天,我一直在关注Maven多模块和EAR项目,它们似乎非常相似,因为它们似乎都定义了一系列其他项目的集合 - 它几乎看起来像EAR项目应该只是一个替代包装多模块项目.
我误解了什么吗?或者这些类型的项目一起工作?
按照Pascal的回答:更新以澄清问题,希望如果不容易理解,这将有所帮助; 对不起它可能没有说得很好,耳朵对我来说有点新鲜......
所以说我有两个项目,一个产生战争,另一个产生实用工具.战争取决于战争,我需要将它们打包成耳朵进行部署.我应该使用带有pom包装类型的项目吗?我想我必须在某个地方使用带有耳包装类型的项目来制作最终的工件,所以我最好只使用带有耳包装的项目,还是带有pom和ear的项目?两者如何,怎么样?
我使用Maven程序集插件为我的多模块项目创建一个程序集.从这个多模块项目构建了两个独立的应用程序,每个应用程序都有一组独立的依赖项.我创建了一个自定义程序集描述符,它使用模块构建及其各自的依赖项组装两个目录(对于每个应用程序).它做的一切都很好,但有一点 - 它将两个模块的依赖关系放到彼此的程序集中.
以下是我的项目的简化版本,具有完全相同的行为.
考虑一个由两个模块和一个组装模块组成的项目:
APP
module1
module2
assembly
Run Code Online (Sandbox Code Playgroud)
我已经添加了纯粹用于演示的依赖项:
com.test.app:module1:jar:1.0
\- commons-cli:commons-cli:jar:1.2:compile
com.test.app:module2:jar:1.0
\- commons-daemon:commons-daemon:jar:1.0.8:compile
Run Code Online (Sandbox Code Playgroud)
这是父POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>app</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
<module>assembly</module>
</modules>
</project>
Run Code Online (Sandbox Code Playgroud)
module1 POM:
<project>
<parent>
<groupId>com.test</groupId>
<artifactId>app</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.app</groupId>
<artifactId>module1</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
module2 POM:
<project>
<parent>
<groupId>com.test</groupId>
<artifactId>app</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.app</groupId>
<artifactId>module2</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>commons-daemon</groupId>
<artifactId>commons-daemon</artifactId>
<version>1.0.8</version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
装配POM:
<project>
<parent>
<groupId>com.test</groupId>
<artifactId>app</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.app</groupId> …Run Code Online (Sandbox Code Playgroud) dependency-management maven maven-assembly-plugin multi-module
我有一个多模块项目,如下所示:
module2中的pom.xml依赖于module1.
当我运行mvn clean编译时,我收到以下错误:
反应堆中的项目包含循环参考.
这是我在module1中的依赖项:
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.48</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚为什么它说有一个循环引用.即使我做了mvn依赖:在module1上的树,我得到以下内容:
[INFO] +- log4j:log4j:jar:1.2.14:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.6.1:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO] +- com.jcraft:jsch:jar:0.1.48:compile
[INFO] \- junit:junit:jar:4.8.2:test
Run Code Online (Sandbox Code Playgroud)
在我看来,在module1中没有对module2的任何引用.那么循环引用来自何处?
编辑:以下是调试日志:
+ Error stacktraces are turned on.
Apache Maven 2.2.1 (r801777; 2009-08-06 15:16:01-0400)
Java version: 1.6.0_31
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"
[INFO] Scanning …Run Code Online (Sandbox Code Playgroud) 目前我们有6个Maven模块:
webappsecuritycore(提供数据库访问User)commonmodule1module2我认为依赖树非常明显:
webapp 取决于一切security 取决于核心core 取决于共同点common 什么都不依赖module1 取决于核心和共同点module2 取决于核心,module1和common现在我想要一些BaseEntity:它应该有一个@PrePersist可以节省电流User.几乎每个实体都会使用它BaseEntity.这就是每个模块依赖的原因core.
而且因为一切都依赖于core,将这BaseEntity也放在core模块中似乎是合乎逻辑的.(即使我更喜欢使用common它,但由于依赖性,这似乎是不可能的).
现在出现问题:要设置当前用户,我必须使用访问权限SecurityContextHolder.getContext().getAuthentication().getPrincipal().但是有了这个,我会有一些不必要的依赖(或者我只是太挑剔了?).
如果我想要自定义实现,问题会变得更糟UserDetails.我应该把它放在哪里?core还是security?或者让User实体实施UserDetails是否常见?我不这么认为.问题出现了,因为在验证用户时,我必须UserDetails在security模块内创建对象.当我想要检索当前时,User我必须将getPrincipal()方法强制转换为自定义UserDetails类.
我真的很困惑如何松散耦合,但也实现了应用程序所需的一切.
我想到的最后一个想法是关于使用依赖注入,但我不知道它是否有效!?(在模块中有一个currentUserBean security,其他人都可以通过它获得它@Autowired MyCustomUserDetails)
所以请帮我把这些东西弄好!
谢谢! :)
背景:
CommonClassA.java.Billtype.java其他模块(EmployeeBilling))是指由此类(CommonClassA.java).问题:
在编译EmployeeBilling模块时,它会抛出
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project EmployeeBilling: Compilation failure
[ERROR] \MyWorkspace\Biz\EmployeeBilling\src\main\java\com\employee\Billtype.java:[79,19] error: cannot access CommonClassA
[ERROR] -> [Help 1]**
Run Code Online (Sandbox Code Playgroud)
支持细节:
EmployeeBilling> pom.xml中定义的依赖项:
公共模块中的其他类似乎可以访问,因为没有观察到错
工具:
提前致谢!
我有一个多模块Maven项目:
root
SubmoduleA
src
pom.xml
SubmoduleB
src
pom.xml
pom.xml
.gitlab-ci.yml
Run Code Online (Sandbox Code Playgroud)
有人在检查只影响SubmoduleA的代码时,是否有任何方法可以仅在SubmoduleA上触发CI管道?例如,某人在SubmoduleA中进行了更改.一旦他们提交并推送,我想在SubmoduleA上自动运行build-> test-> deploy,因为SubmoduleB没有变化.
有没有办法为回购中的特定子模块或子项目指定触发器和作业?
基于this SO question中的以下maven配置,为Maven builds回答,我需要一个等效的代码来设置Gradle。环顾四周,我找不到为 Gradle 执行此操作的设置。
来自其他问题的问题概要:本质上,来自外部项目的类没有被索引,以便 Quarkus 可以使用它们。下面的解决方案重建索引并允许访问类。
来自其他问题的代码:
<build>
<plugins>
<plugin>
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<version>1.0.6</version>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
另外......经过更多的挖掘,似乎这里的工作可能已经有一个修复(github合并请求。在撰写本文时,这是合并的,但看起来不像是发布的一部分。将跟进如果这改变了,如果它解决了这个问题。
随着 的发布0.18.0,我仍然遇到问题,但我相信我更接近了。我仍然收到以下(非常相似)错误:
2019-06-27 19:45:52,741 INFO [io.qua.dep.QuarkusAugmentor] (main) Beginning quarkus augmentation
2019-06-27 19:45:53,241 WARN [io.qua.dep.ste.ReflectiveHierarchyStep] (build-8) Unable to properly register the hierarchy of the following classes for reflection as they are not in the Jandex index:
- com.ebp.reasonadle.shared.pojos.user.User
Consider adding them to the index …Run Code Online (Sandbox Code Playgroud) 几天来我一直在寻找一种解决方案,用于合并Jacoco多模块 Android 项目的多个报告,以便Sonarcloud立即将它们发送出去。我已经检查了大量的 Stackoverflow 帖子和其他内容,例如博客、Github 存储库、Gradle 论坛等,但不幸的是没有一个解决方案适合我。
如果这里有人与我分享示例项目或代码片段,我将非常感激。
Gradle version: 7.0.2
Kotlin version: 1.5.21
JDK: 11
Run Code Online (Sandbox Code Playgroud)
下面的代码片段也不适合我
/**
* Root task that generates an aggregated Jacoco test coverage report for all sub-projects
*/
task jacocoFullReport(type: JacocoReport, group: 'Coverage reports') {
group = 'Reporting'
description = 'Generates an aggregate report from all subprojects'
tasks.withType(Test) {
ignoreFailures true
}
def projects = subprojects
//noinspection GrUnresolvedAccess
dependsOn(projects.jacocoReport)
final source = files(projects.jacocoReport.sourceDirectories)
additionalSourceDirs.setFrom source
sourceDirectories.setFrom source
classDirectories.setFrom files(projects.jacocoReport.classDirectories) …Run Code Online (Sandbox Code Playgroud) 我无法找到一个好的,可扩展的解决方案的问题:
我有一个项目,可以提供给定工件的多种风格.这已被设置为多模块项目,目前有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)
这样做会有意义吗?
更新: …