gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:38:36 30 4
gpt4 key购买 nike

故事:我最近发现设置 jar.enabled = false在多项目 Gradle 项目的项目 b-features 中,将阻止同一项目的项目 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
...

A 类 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.

最佳答案

您实际依赖的是项目生成的工件(JAR 文件)。当您禁用工件的生成(jar 任务)时,当然不再找到所需的类。

关于gradle - 为什么 "jar.enabled = false"会影响 Gradle 中的依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46755551/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com