IDEA-插件开发踩坑记录-第一坑-创建gradle工程编译失败

本文档详细记录了在尝试使用IntelliJ IDEA创建并编译Gradle Java插件时遇到的一系列问题及解决方案。包括Gradle版本不兼容、Java版本需求、默认配置错误等,并提供了具体的解决步骤和配置修改建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


编译失败

通过idea创建gradle-java-idea-plugin
步骤:左上角菜单file->new->project
创建参数
创建成功后执行gradle编译:
第一个异常:编译失败。

Build file 'D:\study_idea_plugin\idea-plugin-sample\test-plugin-gradle-demo\build.gradle' line: 3

An exception occurred applying plugin request [id: 'org.jetbrains.intellij', version: '1.3.1']
> Failed to apply plugin [id 'org.jetbrains.intellij']
   > Could not create an instance of type org.jetbrains.intellij.utils.ArchiveUtils.
      > Could not generate a decorated class for class org.jetbrains.intellij.utils.ArchiveUtils.
         > org/gradle/api/file/ArchiveOperations

问题原因:默认的gradle配置需要gradle-wapper.perperties
问题
解决办法:建议直接改用本地已经下载好的gradle(版本必须6.6及以上,原因后面会提到)即可,我用的是6.9的版本。

Gradle 问题

A problem occurred configuring root project 'test-plugin-gradle-demo'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.3.1.
     Required by:
         project : > org.jetbrains.intellij:org.jetbrains.intellij.gradle.plugin:1.3.1
      > No matching variant of org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.3.1 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally but:
          - Variant 'apiElements' capability org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.3.1 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
          - Variant 'runtimeElements' capability org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.3.1 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8

问题原因:
在这里插入图片描述
如图,idea的插件编译需要使用java11版本1.8版本不行。图里也说了gradle必须为6.6以上版本的原因。
解决办法:gradle的jvm改用11版本。解决办法

默认build.gradle配置文件错误

此处贴出默认生成的build.gradle配置文件

plugins {
    id 'java'
    id 'org.jetbrains.intellij' version '1.3.1'
}

group 'org.example'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
    version '2019.3.1'
}
patchPluginXml {
    changeNotes """
      Add change notes here.<br>
      <em>most HTML tags may be used</em>"""
}

继续编译,出现第三个异常:

Build file 'D:\xxx\test-plugin-gradle-demo\build.gradle' line: 24

A problem occurred evaluating root project 'test-plugin-gradle-demo'.
> No signature of method: build_ciszds7050s7mtk2a9dp1remr.patchPluginXml() is applicable for argument types: (build_ciszds7050s7mtk2a9dp1remr$_run_closure4) values: [build_ciszds7050s7mtk2a9dp1remr$_run_closure4@3e384e3f]

问题原因:这当然是因为这货生成的东西不对导致的呀。

patchPluginXml {
    changeNotes """
      Add change notes here.<br>
      <em>most HTML tags may be used</em>"""
}

解决办法:要么删掉,要么配对。此处也要用key = value 形式编写。
支持的属性见:https://github.com/JetBrains/gradle-intellij-plugin#patching-dsl

继续编译,出现第四个异常:

Failed to calculate the value of task ':setupDependencies' property 'idea'.
Cannot query the value of extension 'intellij' property 'version' because it has no value available.

问题原因:异常里实际上已经说明白了。就是intellij的version没有值。
在这里插入图片描述
解决方法,配置加上=号:(注意这里的版本号根据实际情况来。)

intellij {
    version = '2019.3.1'
}
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值