上項目結構圖:
idea里面一個project其實相當於eclipse的一個workspace,這樣一來就很好理解了,我們新建了兩個module,相當於eclipse的兩個項目工程
主要看配置:build.gradle和根項目settings.gradley以及class
action:
group 'cn.sawshaw' version '1.0-SNAPSHOT' apply plugin: 'java' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { compile project(":service") testCompile group: 'junit', name: 'junit', version: '4.12' }
package action; import service.SayHello; public class HelloAction { public String helloAction(String name){ return new SayHello().sayHello(name); } public static void main(String[] args){ String result=new SayHello().sayHello("小明"); System.out.println(result); } }
Service:
group 'cn.sawshaw' version '1.0-SNAPSHOT' apply plugin: 'java' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' }
package service; public class SayHello { public String sayHello(String name){ System.out.print("service sayHello start ."); return "Hello:"+name; } }
根項目User:
group 'cn.sawshaw' version '1.0-SNAPSHOT' apply plugin: 'java' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { compile project(":action") testCompile group: 'junit', name: 'junit', version: '4.12' }
rootProject.name = 'user' include 'action' include 'service'
package test; import action.HelloAction; public class Test1 { public static void main( String[] args ){ String result= new HelloAction().helloAction("lily"); System.out.println(result); } }
可以看出Action依賴Service,User依賴Action
eclipse自帶了可以構建父子項目工具Gradle STS Project
gradle falt-java-mutiple project