intellij-platform-gradle-plugin
intellij-platform-gradle-plugin copied to clipboard
Cannot publish plugin library to local maven repo: `java.io.FileNotFoundException: <project>/build/libs/<libraryname>-searchableOptions.jar`
What happened?
The build.gradle.kts where this bug is experienced is here: https://github.com/redhat-developer/intellij-common/blob/main/build.gradle.kts#L1
I have a library for IDEA plugins. When launching the gradle taskpublishToLocalMaven I get the following error:
java.io.FileNotFoundException: /<workspace>/<projectname>/build/libs/<projectname-and-version>-searchableOptions.jar
Relevant log output or stack trace
22:51:29: Executing 'publishToMavenLocal'...
Starting Gradle Daemon...
Gradle Daemon started in 705 ms
> Task :initializeIntellijPlatformPlugin
> Task :patchPluginXml NO-SOURCE
> Task :verifyPluginProjectConfiguration UP-TO-DATE
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :generateManifest UP-TO-DATE
> Task :instrumentCode UP-TO-DATE
> Task :jar UP-TO-DATE
> Task :instrumentedJar UP-TO-DATE
> Task :composedJar UP-TO-DATE
> Task :prepareSandbox
> Task :buildSearchableOptions SKIPPED
> Task :prepareJarSearchableOptions SKIPPED
> Task :jarSearchableOptions SKIPPED
> Task :javadoc UP-TO-DATE
> Task :javadocJar UP-TO-DATE
> Task :sourcesJar UP-TO-DATE
> Task :generateMetadataFileForMavenJavaPublication FAILED
14 actionable tasks: 3 executed, 11 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateMetadataFileForMavenJavaPublication'.
> java.io.FileNotFoundException: /Users/adietish/Documents/jboss-workspaces/intellij-common/build/libs/intellij-common-1.9.7-SNAPSHOT-searchableOptions.jar (No such file or directory)
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 7s
22:51:36: Execution finished 'publishToMavenLocal'.
Steps to reproduce
Steps:
- ASSERT: use gradle 8.5 and intellij-gradle-plugin 2.1.0, base-platform is IC-2024.2
- ASSERT: have no
META-INF/plugin.xmlsince it's a library to be used in a IDEA plugin. It's not a plugin. - ASSERT: You dont have a
META-INF/plugin.xml(since it's a library, not a plugin). You disable searchable options because publishing to local maven would complain about a missingplugin.xml:
intellijPlatform {
buildSearchableOptions = false
}
- EXEC: launch gradle tasks
cleanandbuild. ThenpublishToMavenLocal
Result: Publishing fails with the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateMetadataFileForMavenJavaPublication'.
> java.io.FileNotFoundException: <project-dir>/build/libs/<projectname-and-version>-searchableOptions.jar (No such file or directory)
Gradle IntelliJ Plugin version
2.1.0
Gradle version
8.5
Operating System
macOS
Link to build, i.e. failing GitHub Action job
No response
This issue looks related to https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1687
Probably because it is added to runtime elements configuration https://github.com/JetBrains/intellij-platform-gradle-plugin/blob/main/src/main/kotlin/org/jetbrains/intellij/platform/gradle/tasks/JarSearchableOptionsTask.kt#L82
Using from(components["intellijPlatform"]) seems to fix it. I can then get rid of buildSearchableOptions and the jars deployed are correct.
Probably because it is added to runtime elements configuration https://github.com/JetBrains/intellij-platform-gradle-plugin/blob/main/src/main/kotlin/org/jetbrains/intellij/platform/gradle/tasks/JarSearchableOptionsTask.kt#L82
so a simple fix might be to not add it when the buildSearchableOption is set to false ?
I could fix my issue by switching the component from components["java"] to components["intellijPlatform"]. I then could get rid of setting buildSearchableOptions to false and things started to work (jars are now correct).
Closing if you dont mind 😄
Unfortunately I have to reopen this issue. The build works as far as it creates a valid artifact but it's type is wrong. It is creating a composed jar that the plugin cannot consume as such. We need a plain jar instead.
<libraryname>.mode (in my case intellij-common-1.9.7-SNAPSHOT.module):
"variants": [
{
"name": "intellijPlatformComposedJar",
"attributes": {
"org.gradle.category": "library",
"org.gradle.dependency.bundling": "external",
"org.gradle.jvm.environment": "standard-jvm",
"org.gradle.jvm.version": 17,
---> "org.gradle.libraryelements": "composed-jar",
Composed that is a jar which was instrumented by this plugin (e.g. added check for not null args) then it was renamed to have a normal name, again without -instrumented.jar suffix. The non-instrumented jar will have -base.jar. All this are customization of this plugin.
You can fix that metadata any way you want in the consuming project using https://docs.gradle.org/current/userguide/component_metadata_rules.html
How do you consume it exactly?
@AlexanderBartash thanks for chiming in! I consume it in a plugin as a normal dependency, like a lib: https://github.com/redhat-developer/intellij-kubernetes/blob/43b450d76e46b717655872cc5695aeaa469a8580/build.gradle#L38
dependencies {
implementation(
"com.redhat.devtools.intellij:intellij-common:${intellijCommonVersion}",
Do I get you right that I could customize the assemble task, add it a doLast, where I rename the -base.jar to a name without the -base?
@adietish Do I understand your intention correctly? You want to depend on plugin jar as on a regular lib?
Also is this https://repository.jboss.org/nexus/content/repositories/releases/com/redhat/devtools/intellij/intellij-common/1.9.0/intellij-common-1.9.0.module published with 1.x plugin? Because it looks ok.
@adietish Something like this https://github.com/redhat-developer/intellij-kubernetes/pull/802/files It should work, but I could not test, since in the public repo metadata is normal.
What I did in that PR assumes that when you publish the jar it has metadata, it has intellijPlatformComposedJar variant with library elements set to "composed-jar" and that rule changes it to "jar" on your local environment only.
@AlexanderBartash yes, this project is a library (with access to jetbrains platform API) that our plugins consume. We had this already working using the 1.x plugin as you pointed out (current version is 1.9.6). We currently try to get compatible to IC-2024.2+ and thus migrate to 2.x of this plugin.
What I did in that PR assumes that when you publish the jar it has metadata, it has intellijPlatformComposedJar variant with library elements set to "composed-jar" and that rule changes it to "jar" on your local environment only.
Awesome, thanks a lot! Will try this tomorrow.
@AlexanderBartash awesomeness, with your changes, I can consume our composed-jar lib in our plugin. Works like a charm. Thanks a lot!