gpt4 book ai didi

java - gradle 依赖项 : what "classpath" keyword means exactly and where it is documented?

转载 作者:行者123 更新时间:2023-12-02 01:05:54 31 4
gpt4 key购买 nike

我在网络上搜索了“gradle classpath site:stackoverflow.com”和“gradle classpath”,并仅在以下位置找到了相关信息:
Gradle: What is the difference between classpath and compile dependencies?

于腾宝的回答中写道:

compile 'org.hibernate:hibernate-core:5.0.5.Final' is a module dependency declaration. The compile configuration (which is now deprecated by the implementation configuration.) is merely a keyword for Implementation only dependencies. It is not a keyword describing which type of dependency it is (by type here I'm following the three types defined in the tutorial, i.e. module, file, and project.)

据我了解 classpath 也是关键字。我试图在 gradle 文档中找到它的含义: https://docs.gradle.org/current/userguide/declaring_dependencies.html

以及其中引用的其他一些内容:
https://docs.gradle.org/current/userguide/dependency_management_for_java_projects.html https://docs.gradle.org/current/userguide/java_library_plugin.html https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.Configuration.html https://docs.gradle.org/current/userguide/variant_model.html https://docs.gradle.org/current/userguide/java_plugin.html

另外: https://docs.gradle.org/current/javadoc/org/gradle/api/initialization/dsl/ScriptHandler.html https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/Classpath.html https://docs.gradle.org/current/userguide/organizing_gradle_projects.html

其中提到了“compileClasspath”。如果 classpath 关键字仅仅被弃用为 compile 关键字,为什么文档中没有它?

附注我的意思是像:

buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}

回答后添加:

在gradle源代码中搜索getBuildscript(): search for getBuildscript() in gradle source code

最佳答案

So as I understood classpath is also keyword

这是不正确的。 classpathcompileimplementationapi 等等都是 configurations 。 Gradle 中的配置是树状的,这意味着通常每个配置都从某个父级扩展:

configuration tree

来源:https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph

例如,使用实现配置,当您在build.gradle中执行以下操作时:

dependencies {
implementation("org.apache.commons:commons-lang3:3.9")
}

你实际上在做:

project.getDependencies().add("implementation", "org.apache.commons:commons-lang3:3.9")

前者使用Gradle DSL而后者直接使用Gradle API。

If classpath keyword is merely deprecated as compile one, why is it absent from docs?

编译配置已被弃用,如所述here 。仍然使用 classpath 配置,但通常仅与 buildscrpt { } 一起使用 block 。

举个例子:

buildscript {
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")
}
}

脱糖至:

project.getBuildscript().getDependencies().add("classpath", "com.android.tools.build:gradle:3.4.1")

关于java - gradle 依赖项 : what "classpath" keyword means exactly and where it is documented?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60074181/

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