question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I use extraDirectories property correctly in a build.gradle.kts

See original GitHub issue

Environment:

  • Jib version: 2.5.0
  • Build tool: Gradle 6.5.1 (Kotlin 1.3.72, Groovy 2.5.11, Ant 1.10.7, JVM 11.0.8)
  • OS: Ubuntu 20.04.1 LTS

Description of the issue: I tried to use the extraDirectories.paths.path to bundle my native shared libraries, but It always said Val cannot be reassigned. How can I fix it?

Steps to reproduce:

  1. Generate a simple gradle project using gradle init --type java-application.
  2. Add a jib configuration in build.gradle.kts.
  3. Run ./gradlew jibDockerBuild

jib-gradle-plugin Configuration:

A short part of my build.gradle.kts.

    
jib {
    from.image = "openjdk:14"
    to.image = "simple_test"
    to.tags = setOf("$version")
    container {
        mainClass = "some.simple.project.App"
        jvmFlags = listOf("-Djava.library.path=${jib.container.appRoot}/native-libs")
        creationTime = "USE_CURRENT_TIMESTAMP"
    }
    extraDirectories {
        //paths.add(ExtraDirectoryParameters("native-libs/linux-amd64", "${jib.container.appRoot}/native-libs"))
        paths {
            path {
                from = "native-libs/linux-amd64"
                into = "${jib.container.appRoot}/native-libs"   
            }
        }
    }
}

Log output:

✦ ❯ ./gradlew jibDockerBuild 

> Configure project :
e: /home/xx/Projects/XX/build.gradle.kts:109:17: Val cannot be reassigned
e: /home/xx/Projects/XX/build.gradle.kts:109:24: Type mismatch: inferred type is String but Path! was expected

FAILURE: Build failed with an exception.

* Where:
Build file '/home/xx/Projects/XX/build.gradle.kts' line: 109

* What went wrong:
Script compilation errors:

  Line 109:                 from = "native-libs/linux-amd64"
                            ^ Val cannot be reassigned

  Line 109:                 from = "native-libs/linux-amd64"
                                   ^ Type mismatch: inferred type is String but Path! was expected

2 errors

* 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 909ms

Additional Information: I use Gradle kotlin DSL now.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
chanseokohcommented, Aug 21, 2020

@hwiorn thanks for the report. Looks like this is something we overlooked, as we don’t have a lot of experience with Kotlin. Can’t really understand the exact reason why Kotlin doesn’t allow this, but for now, you can explicitly call ExtraDirectoryParameters.setFrom(Object), which I confirmed works.

    extraDirectories {
        paths {
            path {
                setFrom("native-libs/linux-amd64")
                into = "${jib.container.appRoot}/native-libs"   
            }
        }
    }
1reaction
chanseokohcommented, Aug 24, 2020

Glad it worked. We will keep this open to track the issue with Kotlin.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gradle Kotlin DSL Primer
Many of the objects, functions and properties you use in your build scripts come from the Gradle API and the APIs of the...
Read more >
Is there a way to define property to be used in both settings ...
$rootDir/module/build.gradle.kts // This will take existing dependency from extra val springBootVersion: String by extra dependencies ...
Read more >
Containerising Kotlin with Jib - The blog of Peter Evans
Here is a quick introduction of how to use Jib with Gradle's Kotlin DSL. A complete example project is contained in this repository....
Read more >
Micronaut Gradle plugin
The most simple Kotlin build using a build.gradle(.kts) file looks like: Groovy Kotlin. plugins { id "org.jetbrains.kotlin.jvm" version "1.6.21" id ...
Read more >
5 reasons to switch to the Gradle Kotlin DSL - Tom Gregory
The Gradle Kotlin DSL has simplified syntax via property extensions ... \custom-task\build.gradle.kts:7:5: Unresolved reference: toolVersion.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found