我有这个架构
mmsb
|----pom.xml (packaging : pom) -> declare modules API and Utils
|----api
| |----pom.xml (packaging : pom) -> declare module api-slack / parent project
| |----api-slack
| |----pom.xml (packaging : pom) -> declare module api-slack-core / parent api
| |----api-slack-core
| |----pom.xml (packaging : jar) -> java code / parent api-slack
|----utils
| |----pom.xml (packaging : jar) -> java code / parent project / has dependency from api-slack-core
|
它不起作用
从Maven干净安装说:
~/dev/maven-multi-sub-projets ⌚ 11:03:48
$ mvn clean install -DskipTests
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] mmsb
[INFO] api
[INFO] api-slack
[INFO] api-slack-core
[INFO] utils
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mmsb 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ mmsb ---
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ mmsb ---
[INFO] Installing /home/mario/dev/maven-multi-sub-projets/pom.xml to /opt/maven/m2repo/fr/app/mmsb/1.0-SNAPSHOT/mmsb-1.0-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building api 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ api ---
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ api ---
[INFO] Installing /home/mario/dev/maven-multi-sub-projets/api/pom.xml to /opt/maven/m2repo/fr/app/api/1.0-SNAPSHOT/api-1.0-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building api-slack 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ api-slack ---
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ api-slack ---
[INFO] Installing /home/mario/dev/maven-multi-sub-projets/api/api-slack/pom.xml to /opt/maven/m2repo/fr/app/api-slack/1.0-SNAPSHOT/api-slack-1.0-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building api-slack-core 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ api-slack-core ---
[INFO] Deleting /home/mario/dev/maven-multi-sub-projets/api/api-slack/api-slack-core/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ api-slack-core ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ api-slack-core ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /home/mario/dev/maven-multi-sub-projets/api/api-slack/api-slack-core/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ api-slack-core ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ api-slack-core ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ api-slack-core ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ api-slack-core ---
[INFO] Building jar: /home/mario/dev/maven-multi-sub-projets/api/api-slack/api-slack-core/target/api-slack-core-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:1.4.2.RELEASE:repackage (default) @ api-slack-core ---
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ api-slack-core ---
[INFO] Installing /home/mario/dev/maven-multi-sub-projets/api/api-slack/api-slack-core/target/api-slack-core-1.0-SNAPSHOT.jar to /opt/maven/m2repo/fr/app/api-slack-core/1.0-SNAPSHOT/api-slack-core-1.0-SNAPSHOT.jar
[INFO] Installing /home/mario/dev/maven-multi-sub-projets/api/api-slack/api-slack-core/pom.xml to /opt/maven/m2repo/fr/app/api-slack-core/1.0-SNAPSHOT/api-slack-core-1.0-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building utils 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ utils ---
[INFO] Deleting /home/mario/dev/maven-multi-sub-projets/utils/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ utils ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ utils ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/mario/dev/maven-multi-sub-projets/utils/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/mario/dev/maven-multi-sub-projets/utils/src/main/java/fr/app/utils/Application.java:[3,29] package fr.app.api.slack.core does not exist
[ERROR] /home/mario/dev/maven-multi-sub-projets/utils/src/main/java/fr/app/utils/Application.java:[11,13] cannot find symbol
symbol: class SlackService
location: class fr.app.utils.Application
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] mmsb ............................................... SUCCESS [ 0.213 s]
[INFO] api ................................................ SUCCESS [ 0.005 s]
[INFO] api-slack .......................................... SUCCESS [ 0.004 s]
[INFO] api-slack-core ..................................... SUCCESS [ 1.558 s]
[INFO] utils .............................................. FAILURE [ 0.113 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.197 s
[INFO] Finished at: 2016-12-15T11:03:52+01:00
[INFO] Final Memory: 32M/317M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project utils: Compilation failure: Compilation failure:
[ERROR] /home/mario/dev/maven-multi-sub-projets/utils/src/main/java/fr/app/utils/Application.java:[3,29] package fr.app.api.slack.core does not exist
[ERROR] /home/mario/dev/maven-multi-sub-projets/utils/src/main/java/fr/app/utils/Application.java:[11,13] cannot find symbol
[ERROR] symbol: class SlackService
[ERROR] location: class fr.app.utils.Application
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :utils
如何在utils中声明api-slack-core的依赖性?
更新
我在此存储库中上传代码:https://github.com/mmaryo/mmsb
问题是我在fr.app.utils.Application里面导入fr.app.api.slack.core.SlackService
更新2
我发现了问题,我删除了:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
答案 0 :(得分:1)
这里很少 -
在父 pom级别(project
),为什么还要声明parent
?
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
也是
<packaging>pom</packaging>
以及为什么你有
<module>api-slack</module>
<module>api-slack-core</module>
如果他们应该在api
范围内分层次地 - > api-slack
- &gt; api-slack-core
。作为改进,请在module
级别内移出project
。
然后在 Api
级别,我怀疑Api
目前是否正在使用不正确的父名称构建 -
<parent>
<groupId>fr.app</groupId>
<artifactId>vishnou</artifactId> <!-- modified -->
<version>1.0-SNAPSHOT</version>
</parent>
Api-slack 似乎很好。
Api-slack-core 可以摆脱多余的空白
<dependencies></dependencies>
并指定plugin
的版本(除非已在任何父poms中定义)为 -
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>x.y.z</version>
</plugin>
进一步 Utils 可以使用Api-slack-core
作为依赖项,也请更改
<groupId>fr.app</groupId>
<artifactId>utils</artifactId> <!--changed-->
总的来说,我建议您按照multi module example的建议来完成guide。
答案 1 :(得分:0)
尝试运行// creates a tree from a flat set of hierarchically related data
var MiracleGrow = function(treeData, key, parentKey)
{
var keys = [];
treeData.map(function(x){
x.Children = [];
keys.push(x[key]);
});
var roots = treeData.filter(function(x){return keys.indexOf(x[parentKey])==-1});
var nodes = [];
roots.map(function(x){nodes.push(x)});
while(nodes.length > 0)
{
var node = nodes.pop();
var children = treeData.filter(function(x){return x[parentKey] == node[key]});
children.map(function(x){
node.Children.push(x);
nodes.push(x)
});
}
if (roots.length==1) return roots[0];
return roots;
}
// demo/test data
var treeData = [
{id:9, name:'Led Zep', parent:null},
{id:10, name:'Jimmy', parent:9},
{id:11, name:'Robert', parent:9},
{id:12, name:'John', parent:9},
{id:8, name:'Elec Gtr Strings', parent:5},
{id:1, name:'Rush', parent:null},
{id:2, name:'Alex', parent:1},
{id:3, name:'Geddy', parent:1},
{id:4, name:'Neil', parent:1},
{id:5, name:'Gibson Les Paul', parent:2},
{id:6, name:'Pearl Kit', parent:4},
{id:7, name:'Rickenbacker', parent:3},
{id:100, name:'Santa', parent:99},
{id:101, name:'Elf', parent:100},
];
var root = MiracleGrow(treeData, "id", "parent")
console.log(root)
?其中mvn clean install -pl Utils -am
是父pom中模块的名称。
Maven Reactor应该自己找出依赖关系 - 你只需要放置依赖关系的GAV(groupid,artifactid,version)。