编译失败
通过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'
}