【问题标题】:Could not get unknown property 'runtime' for configuration container of type org.gradle.api.internal.artifacts.configurations无法获取 org.gradle.api.internal.artifacts.configurations 类型的配置容器的未知属性“运行时”
【发布时间】:2020-02-21 14:20:27
【问题描述】:

当我遵循how to copy all source jars using gradle 的答案时,我遇到了错误(Could not get unknown property 'runtime' for configuration container of type org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.),添加了以下内容代码 build.gradle 并在 IJ IDEA 中运行该任务:

task copySourceJars( type: Copy ) {
  def sources = configurations.runtime.resolvedConfiguration.resolvedArtifacts.collect { artifact ->
    project.dependencies.create( [
      group: artifact.moduleVersion.id.group,
      name: artifact.moduleVersion.id.name,
      version: artifact.moduleVersion.id.version,
      classifier: 'sources'
    ] )
  }
  from configurations.detachedConfiguration( sources as Dependency[] )
    .resolvedConfiguration.lenientConfiguration.getFiles( Specs.SATISFIES_ALL )
  into file( 'some-directory/' )
}

我对错误进行了网络搜索,但仅在 stackoverflow 上找到 Gradle - Could not get unknown property 'scm' for configuration container,建议添加配置,就像我在阅读该帖子后所做的那样:

configurations {
    runtime
}

在任务copySourceJars 运行之后,它写了BUILD SUCCESSFUL,但没有文件出现在硬盘驱动器的特定目录中。出于某种原因构建输出未列出copySourceJars

Executing tasks: [:app:generateDebugSources]

Gradle Daemon started in 1 s 427 ms
> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:checkDebugManifest UP-TO-DATE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:prepareLintJar UP-TO-DATE
> Task :app:generateDebugSources UP-TO-DATE

BUILD SUCCESSFUL in 9s
4 actionable tasks: 4 up-to-date

然后我再次从 IDEA 菜单中选择run 并得到另一个错误:

无法为 dulrvlqnmf04w7h3gseaejvhm 打开初始化重新映射的类缓存 (/Users/user/.gradle/caches/5.2.1/scripts-remapped/ijresolvers_8btlazswoejgb1uwugudd695x/dulrvlqnmf04w7h3gseaejvhm/init3ca90766b0adfce53d4b035e7e9dc5fe)。

无法为初始化脚本“/private/var/folders/g7/2zrjv4hd04v4vkhkbm3stchjwwbz27/T/ijresolvers.gradle”打开初始化通用类缓存 (/Users/user/.gradle/caches/5.2.1/scripts/dulrvlqnmf04w7h3gseaejvhm/init/init3ca90766b0adfce53d4b035e7e9dc5fe)。 漏洞!源单元“BuildScript”中阶段“语义分析”中的异常不受支持的类文件主要版本 57

我是否正确地使用 IJ IDEA 下载依赖项?可能是添加配置runtime没有正确完成?

【问题讨论】:

  • 你能解决这个问题吗?
  • 根据stackoverflow.com/a/66910991/5158636,我将 runtime 更改为 runtimeOnly,虽然这是 Gradle 7 更新的一部分,但这似乎与 Gradle 5 有关。

标签: java gradle intellij-idea


【解决方案1】:

这是因为你的 gradle 版本和 gradle7 的不同。从 Gradle 6.x 开始,使用参数configurations.runtime 来获取程序执行的配置被禁用。相反,您可以使用configurations.runtimeClasspath 来实现相同的功能。 Gradle7 docs 之后编译成功,得到了项目的真实结构。

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.1/userguide/command_line_interface.html#sec:command_line_warnings

Project Constructure

【讨论】:

    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      • 2020-06-15
      相关资源
      最近更新 更多