【问题】【Maven】Linux环境下Maven打包问题 —— 提示找不到子模块
探究完,我都想抽自己嘴巴子了~
背景
父级pom.xml:
...
<modules>
<module>GOF</module>
</modules>
...
子模块pom.xml:
...
<artifactId>GOF</artifactId>
...
异常
”[ERROR] Child module /data/git/java-demo/GOF of /data/git/java-demo/pom.xml does not exist @ “
[root@devops java-demo]mvn clean install -e -Dmaven.test.skip=true -f pom.xml
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 13, column 21
[ERROR] Child module /data/git/java-demo/GOF of /data/git/java-demo/pom.xml does not exist @
@
[ERROR] The build could not read 1 project -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 13, column 21
[ERROR] Child module /data/git/java-demo/GOF of /data/git/java-demo/pom.xml does not exist @
at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:397)
at org.apache.maven.graph.DefaultGraphBuilder.collectProjects (DefaultGraphBuilder.java:414)
at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor (DefaultGraphBuilder.java:405)
at org.apache.maven.graph.DefaultGraphBuilder.build (DefaultGraphBuilder.java:82)
at org.apache.maven.DefaultMaven.buildGraph (DefaultMaven.java:507)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:219)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
[ERROR] The project com.dongle:practice:1.0.0 (/data/git/java-demo/pom.xml) has 1 error
[ERROR] Child module /data/git/java-demo/GOF of /data/git/java-demo/pom.xml does not exist
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
说明
- 模块有大写字符Linux下Maven打包就会失败,Windows无异常
- 模块修改成小写字符,打包成功。
探究
跟进异常栈信息:
- org.codehaus.plexus.classworlds.launcher.Launcher.main mvn命令入口
- org.apache.maven.DefaultMaven.execute 执行mvn命令
- org.apache.maven.DefaultMaven.buildGraph 构建项目图谱
- org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor 生成maven项目执行/执行器
- org.apache.maven.graph.DefaultGraphBuilder.collectProjects 收集验证项目信息
- org.apache.maven.project.DefaultProjectBuilder.build 生成MavenProject项目信息,每个Module也是一个MavenProject
在build内部执行逻辑有这样一段逻辑:
if (recursive) {
File basedir = pomFile.getParentFile();
List<File> moduleFiles = new ArrayList<>();
for (String module : model.getModules()) {
if (StringUtils.isEmpty(module)) {
continue;
}
module = module.replace('\\', File.separatorChar).replace('/', File.separatorChar);
File moduleFile = new File(basedir, module);
if (moduleFile.isDirectory()) {
moduleFile = modelProcessor.locatePom(moduleFile);
}
if (!moduleFile.isFile()) {
ModelProblem problem = new DefaultModelProblem(
"Child module " + moduleFile + " of " + pomFile + " does not exist",
ModelProblem.Severity.ERROR,
ModelProblem.Version.BASE,
model,
-1,
-1,
null);
result.getProblems().add(problem);
noErrors = false;
continue;
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
// we don't canonicalize on unix to avoid interfering with symlinks
try {
moduleFile = moduleFile.getCanonicalFile();
} catch (IOException e) {
moduleFile = moduleFile.getAbsoluteFile();
}
} else {
moduleFile = new File(moduleFile.toURI().normalize());
}
if (aggregatorFiles.contains(moduleFile)) {
StringBuilder buffer = new StringBuilder(256);
for (File aggregatorFile : aggregatorFiles) {
buffer.append(aggregatorFile).append(" -> ");
}
buffer.append(moduleFile);
ModelProblem problem = new DefaultModelProblem(
"Child module " + moduleFile + " of " + pomFile + " forms aggregation cycle " + buffer,
ModelProblem.Severity.ERROR,
ModelProblem.Version.BASE,
model,
-1,
-1,
null);
result.getProblems().add(problem);
noErrors = false;
continue;
}
moduleFiles.add(moduleFile);
}
好吧,找到这里我好像知道哪里问题了,真是干脆!
忘了windows文件系统不区分大小写了,linux文件系统命名时区分大小写的!!!
定位
项目的GOF模块的目录名是gof
!Linux区分到消息,导致module找不到对应的module目录。这时间浪费的,毫无意义,奇葩行为!
解决
- 保险方案:模块名和目录名一致,建议还是都小写吧,不要奇葩行为了!