Skip to content

Gradle: Fix dependency resolution #11943

Closed

Description

@mvysny

The Gradle plugin needs to gather all jars in order to perform a classpath scan and analyze the npm-related java annotations.

Currently, this is done in the vaadinPrepareFrontend task: a set of dependencies is figured out, from that a set of projects, from that a set of assemble tasks producing those jars. However, this does not work reliably:

  1. Doesn't work for transitive implementation dependencies
  2. Doesn't work if the jar file was not produced by assemble task.

Solution is to simplify the code and take advantage of the fact that Gradle can depend on a FileCollection. The line in the VaadinPrepareFrontendTask class will then simplify to

dependsOn(project.configurations.runtimeClasspath.jars)

/**
 * Returns the "runtimeClasspath" file collection.
 */
internal val ConfigurationContainer.runtimeClasspath: Configuration
    get() = getByName("runtimeClasspath")

/**
 * Returns only jar files from given file collection.
 */
internal val Configuration.jars: FileCollection
    get() = filter { it.name.endsWith(".jar", true) }

See this commit for more details: vaadin/vaadin-gradle-plugin@62211df

(Possible) steps to reproduce:

Have a Gradle multiproject which contains WAR project which implementation-depends on another project which implementation-depends on another project. At the moment the plugin will not not depend on the third project but will still try to read the outcome jar of that project, leading to the following exception:

Caused by: java.lang.IllegalStateException: xyz.jar doesn't exist
        at com.vaadin.gradle.GradlePluginAdapter.getClassFinder(GradlePluginAdapter.kt:68)
        at com.vaadin.flow.plugin.base.BuildFrontendUtil.prepareFrontend(BuildFrontendUtil.java:137)
        at com.vaadin.gradle.VaadinPrepareFrontendTask.vaadinPrepareFrontend(VaadinPrepareFrontendTask.kt:71)

Activity

  1. denis-anisimov commented on Sep 28, 2021

    @denis-anisimov
    Contributor

    VaadinPrepareFrontendTask is in the vaadin/vaadin-gradle-plugin repo along with the gradle plugin code.
    So should this ticket be created in this repo instead ?
    Should I move it there?

  2. mvysny commented on Sep 29, 2021

    @mvysny
    MemberAuthor

    Please keep the ticket here. The reason is that there are two codebases:

    I have performed the fix on the unofficial plugin; however the same fix needs to be performed on the official plugin as well.

  3. denis-anisimov commented on Sep 29, 2021

    @denis-anisimov
    Contributor

    Ah, OK.
    Thanks for explanation.

  4. added 2 commits that reference this issue on Oct 5, 2021
    b449d98
    c0a0ae2
  5. added a commit that references this issue on Oct 11, 2021
    59139f7
  6. added a commit that references this issue on Oct 11, 2021
    1ee6c42
  7. added a commit that references this issue on Oct 12, 2021
    4980a93
  8. vaadin-bot commented on Oct 15, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 22.0.0.alpha8 and is also targeting the upcoming stable 22.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions