nebula-plugins / gradle-ospackage-plugin

Gradle plugin for constructing linux packages, specifically RPM and DEBs.
Apache License 2.0
369 stars 129 forks source link

In Gradle 8.0, plugin doesn't work together with gradle-docker-plugin #421

Open 3ric-T opened 1 year ago

3ric-T commented 1 year ago

Expected Behavior

As a user of gradle-ospackage-plugin plugin, I want to have a plugin which runs together with latest version of gradle-docker-plugin under version 8.0 of gradle wrapper So that I can build both Docker images and RPM packages of my application in the same project

Current Behavior

Build fails with the following error:

Build file '/home/erict/workspaces_xxx/xxx/build.gradle.kts' line: 13

An exception occurred applying plugin request [id: 'com.bmuschko.docker-remote-api', version: '9.2.1']
> Failed to apply plugin 'com.bmuschko.docker-remote-api'.
   > Using internal convention mapping with a Provider backed property.
     Consult the upgrading guide for further information: https://docs.gradle.org/8.0/userguide/upgrading_version_7.html#convention_mapping

Partial stacktrace is:

* Exception is:
org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'com.bmuschko.docker-remote-api', version: '9.2.1']
    (...)
    at Program.execute(Unknown Source)
    (...)
    at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:130)
    at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:42)
    (...)
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin 'com.bmuschko.docker-remote-api'.
    ... 189 more
Caused by: org.gradle.api.GradleException: Using internal convention mapping with a Provider backed property. Consult the upgrading guide for further information: https://docs.gradle.org/8.0/userguide/upgrading_version_7.html#convention_mapping
    (...)
    com.netflix.gradle.plugins.docker.OsPackageDockerBasePlugin$_createTasks_closure1.doCall(OsPackageDockerBasePlugin.groovy:43)
    (...)
    at com.netflix.gradle.plugins.docker.OsPackageDockerBasePlugin.createTasks(OsPackageDockerBasePlugin.groovy:41)
    (...)
    at com.netflix.gradle.plugins.docker.OsPackageDockerBasePlugin.this$dist$invoke$1(OsPackageDockerBasePlugin.groovy)
    at com.netflix.gradle.plugins.docker.OsPackageDockerBasePlugin$2.methodMissing(OsPackageDockerBasePlugin.groovy)
    (...)
    at com.netflix.gradle.plugins.docker.OsPackageDockerBasePlugin$2.execute(OsPackageDockerBasePlugin.groovy:33)
    at com.netflix.gradle.plugins.docker.OsPackageDockerBasePlugin$2.execute(OsPackageDockerBasePlugin.groovy)
    ... 192 more

Full stacktrace is attached to the issue

With version 7.6 of Gradle, there is no issue. It seems that you are using an outdated version of docker-remote-api in root build.gradle file:

implementation 'com.bmuschko:gradle-docker-plugin:3.2.1'

and it can be related to the deprecation of some convention mapping as stated in the error message.

Context

Simple declaration of the plugin, via version catalog file libs.versions.toml:

[versions]
dockerRemoteApiPluginVersion  = "9.2.1"
ospackagePluginVersion        = "11.0.0"  # Released on 04 Jan 2023

[libraries]

[bundles]

[plugins]
dockerRemoteApi = { id = "com.bmuschko.docker-remote-api", version.ref="dockerRemoteApiPluginVersion" }
osPackage       = { id = "com.netflix.nebula.ospackage", version.ref="ospackagePluginVersion" }

Steps to Reproduce (for bugs)

Just declare the plugin as above in build file with Kotlin DSL. Any call to a Gradle task make it fail. IntelliJ IDEA project is attached to the issue, so that the bug can be easily reproduced.

Your Environment

Gradle 8.0 Openjdk version "17.0.5"

3ric-T commented 1 year ago
karbi commented 1 year ago

@3ric-T Thanks for submitting this issue

I have the same problem. Unfortunately I'm not familiar enough with plugin development to resolve this properly. However I come with workaround and decided to use some ugly hack to resolve this ASAP. I'm using only part of `gradle.ospackage.plugin', so I'm not applying it, but manually registering only required parts. I wasn't testing generated package yet, but it looks valid. Here is part of my build.gradle script:

plugins {
    id 'com.netflix.nebula.ospackage' version '11.0.0' apply false
    id 'com.bmuschko.docker-remote-api' version '9.2.1'
    id 'java'
}

var extension = project.extensions.create('ospackage', com.netflix.gradle.plugins.packaging.ProjectPackagingExtension, project)
com.netflix.gradle.plugins.rpm.RpmPlugin.applyAliases(extension)
project.plugins.apply(com.netflix.gradle.plugins.rpm.RpmPlugin)
project.tasks.register('buildRpm', com.netflix.gradle.plugins.rpm.Rpm)
3ric-T commented 1 year ago

Thanks for this workaround, @karbi ! It will be very useful, indeed, as you, I'm using only the RPM part of the ospackage plugin. On the other hand, it seems that the affected lines are in an abandoned piece of code. Instead of deleting this part, I tried to comment out the line that caused the error. After that, it works perfectly with the docker plugin. So I intend to submit a patch in the next few days to fix this problem.

gjvoosten commented 1 year ago

@3ric-T Anything happening on this issue?

3ric-T commented 1 year ago

@gjvoosten No news unfortunately.

We finally migrate from

[versions]
ospackagePluginVersion        = "11.0.0"

[plugins]
osPackage       = { id = "com.netflix.nebula.ospackage", version.ref="ospackagePluginVersion" }

to

[versions]
ospackagePluginVersion        = "11.3.0"

[plugins]
osPackage       = { id = "com.netflix.nebula.rpm", version.ref = "ospackagePluginVersion" }``` 

which seems to be the RPM dedicated part of the preceding but packaged alone. So it does not suffer from the bug.

gjvoosten commented 1 year ago

Thanks @3ric-T, as it happens we also only need Rpm, so we'll be making the same change.