为什么 "jar.enabled = false" 会影响 Gradle 中的依赖项?

why "jar.enabled = false" affects dependencies in Gradle?

故事: 我最近发现在多项目 Gradle 项目的项目 b-features 中设置 jar.enabled = false 将阻止同一项目的项目 a-features 能够通过

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

问题: 为什么 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    
...

Class a-features 项目中的 A:

package outerproject;

import innerproject.B;

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

Class b-features 项目中的 B:

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.

您实际依赖的是项目生成的工件(JAR 文件)。由于您禁用了工件的生成(jar 任务),因此不再能找到所需的 类。