intellij-platform-gradle-plugin icon indicating copy to clipboard operation
intellij-platform-gradle-plugin copied to clipboard

Cannot publish plugin library to local maven repo: `java.io.FileNotFoundException: <project>/build/libs/<libraryname>-searchableOptions.jar`

Open adietish opened this issue 1 year ago • 15 comments

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:

  1. ASSERT: use gradle 8.5 and intellij-gradle-plugin 2.1.0, base-platform is IC-2024.2
  2. ASSERT: have no META-INF/plugin.xml since it's a library to be used in a IDEA plugin. It's not a plugin.
  3. 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 missing plugin.xml:
intellijPlatform {
    buildSearchableOptions = false
}
  1. EXEC: launch gradle tasks clean and build. Then publishToMavenLocal

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

adietish avatar Oct 16 '24 21:10 adietish

This issue looks related to https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1687

adietish avatar Oct 16 '24 21:10 adietish

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

AlexanderBartash avatar Oct 17 '24 00:10 AlexanderBartash

Using from(components["intellijPlatform"]) seems to fix it. I can then get rid of buildSearchableOptions and the jars deployed are correct.

adietish avatar Oct 17 '24 10:10 adietish

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 ?

sbouchet avatar Oct 17 '24 10:10 sbouchet

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 😄

adietish avatar Oct 17 '24 13:10 adietish

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",

adietish avatar Oct 17 '24 17:10 adietish

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.

AlexanderBartash avatar Oct 17 '24 17:10 AlexanderBartash

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 avatar Oct 17 '24 17:10 AlexanderBartash

@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 avatar Oct 17 '24 17:10 adietish

@adietish Do I understand your intention correctly? You want to depend on plugin jar as on a regular lib?

AlexanderBartash avatar Oct 17 '24 18:10 AlexanderBartash

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.

AlexanderBartash avatar Oct 17 '24 18:10 AlexanderBartash

@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.

AlexanderBartash avatar Oct 17 '24 18:10 AlexanderBartash

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 avatar Oct 17 '24 18:10 AlexanderBartash

@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.

adietish avatar Oct 17 '24 19:10 adietish

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.

adietish avatar Oct 17 '24 19:10 adietish

@AlexanderBartash awesomeness, with your changes, I can consume our composed-jar lib in our plugin. Works like a charm. Thanks a lot!

adietish avatar Oct 21 '24 11:10 adietish