2016-12-14 51 views
1

Maven的依賴我有這個架構與子多模塊

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 

如何聲明API-的依賴utils中的slack-core?

UPDATE

我上傳的代碼在這個倉庫:https://github.com/mmaryo/mmsb

問題是,當我輸入fr.app.api.slack.core.SlackService內fr.app.utils.Application

更新2

我發現這個問題,我刪除了:

 <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
+0

你是否已經從根模塊執行'mvn clean install'? – davidxxx

+0

是的,它是乾淨的從根安裝 – Maryo

+0

好的。你可以展示Utils和Api-slack-core模塊的pom嗎? – davidxxx

回答

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 - >api-slack-core。作爲改進,請將module移出project級別。


然後在Api水平,我懷疑怎麼連Api與不正確的父名目前正在建設 -

<parent> 
    <groupId>fr.app</groupId> 
    <artifactId>vishnou</artifactId> <!-- modified --> 
    <version>1.0-SNAPSHOT</version> 
</parent> 

API-鬆弛似乎罰款。


API-鬆弛核可以擺脫多餘的空

<dependencies></dependencies> 

plugin指定版本(除非在父勁歌已經定義) -

<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 exampleguide的建議爲好。

+0

vishnou是項目的名稱,我糾正它,因爲我更改名稱爲stackoverflow – Maryo

+0

spring-boot-starter-parent是我父母(vishnou)的父母,因爲我使用彈簧引導https://projects.spring.io/spring-boot/ – Maryo

+0

我在我的郵件中更正了pom.xml,謝謝nullpointer – Maryo

0

試試運行mvn clean install -pl Utils -am?其中Utils是parent-pom中模塊的名稱。

Maven Reactor應該自己找出依賴關係 - 您只需要放置依賴關係的GAV(groupid,artifactid,version)。這裏