2017-10-15 130 views
0

故事: 我最近發現,在項目設置jar.enabled = false多項目搖籃項目將停止從能指B類項目在同一個項目的-功能通過爲什麼「jar.enabled = false」會影響Gradle中的依賴關係?

dependencies { 
    compile project(':b-features') 
} 

B-功能問題: 爲什麼jar.enabled = false停止項目A成功引用項目B?

附加信息:

根項目的build.gradle:

group 'gradle.studies' 
apply plugin: 'java' 
... 

settings.gradle根項目:

rootProject.name = 'multi-project-reference' 
include 'a-features' 
include 'b-features' 

的build.gradle項目a-features的:

group 'gradle.studies' 
apply plugin: 'java' 
... 
dependencies { 
    compile project(':b-features') 
} 
... 

的build.gradle項目b-features

group 'gradle.studies' 
apply plugin: 'java'  
jar.enabled = false  
... 

一類在a-features項目:

package outerproject; 

import innerproject.B; 

public class A { 
    public static void main(String[] args) { 
     B b = new B(); 
     System.out.println(b.getMsg()); 
    } 
} 

B類中b-features項目:

package innerproject; 
public class B { 

    public B() { 
     this.msg = "Hello World"; 
    } 

    private String msg; 

    public String getMsg() { 
     return msg; 
    } 
    //... 
} 

錯誤:

14:27:50: Executing external task 'build'... 
:compileJava NO-SOURCE :processResources NO-SOURCE :classes UP-TO-DATE 
:jar UP-TO-DATE :assemble UP-TO-DATE :compileTestJava NO-SOURCE 
:processTestResources NO-SOURCE :testClasses UP-TO-DATE :test 
NO-SOURCE :check UP-TO-DATE :build UP-TO-DATE :b-features:compileJava 
UP-TO-DATE :b-features:processResources NO-SOURCE :b-features:classes 
UP-TO-DATE :b-features:jar SKIPPED 
/home/nikita/IdeaProjects/multi-project-reference/a-features/src/main/java/outerproject/A.java:3: 
error: package innerproject does not exist import innerproject.B; 
       ^/home/nikita/IdeaProjects/multi-project-reference/a-features/src/main/java/outerproject/A.java:7: 
error: cannot find symbol 
     B b = new B(); 
     ^ symbol: class B location: class A /home/nikita/IdeaProjects/multi-project-reference/a-features/src/main/java/outerproject/A.java:7: 
error: cannot find symbol 
     B b = new B(); 
       ^ symbol: class B location: class A 3 errors :a-features:compileJava FAILED 

FAILURE: Build failed with an exception. 

回答

2

您實際所依賴的是由項目生成的工件(JAR文件)。當你禁用了神器的產生(jar任務)時,所需的課程不再被發現。