Search code examples
gradlegradle-plugin

Gradle GitHub Dependency plugin not finding dependencies


I configured a GitHub workflow to collect & submit the Gradle dependencies using gradle-build-action, which in turn uses github-dependency-graph-gradle-plugin. For some repos this worked just fine, but for one repo it found nothing. I'm expecting to see the javafx dependencies listed. How do I troubleshoot this?

This repo is running Gradle v 8.2.1

Here is the pertinent part of the GitHub workflow:

      - name: Setup Gradle to generate and submit dependency graphs
        uses: gradle/gradle-build-action@v2
        with:
          dependency-graph: generate-and-submit

      - name: Run a build, generating the dependency graph from 'runtimeClasspath' configurations
        run: ./gradlew build --exclude-task test
        env:
          DEPENDENCY_GRAPH_INCLUDE_CONFIGURATIONS: runtimeClasspath

This is the output from .\gradlew touchtime:dependencies --configuration runtimeClasspath:

------------------------------------------------------------
Project ':touchtime'
------------------------------------------------------------

runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.openjfx:javafx-base:15
+--- org.openjfx:javafx-graphics:15
|    \--- org.openjfx:javafx-base:15
+--- org.openjfx:javafx-controls:15
|    \--- org.openjfx:javafx-graphics:15 (*)
+--- org.openjfx:javafx-fxml:15
|    \--- org.openjfx:javafx-controls:15 (*)
+--- org.openjfx:javafx-swing:15
|    \--- org.openjfx:javafx-graphics:15 (*)
+--- org.controlsfx:controlsfx:8.40.12
\--- org.openjfx:javafx:15.0.1

And this is the resulting JSON file from the dependency plugin:

{
  "version" : 0,
  "job" : {
    "id" : "5977018633",
    "correlator" : "dependencies-depend-submit"
  },
  "sha" : "7c7f4c854a2a5129ff0776b017b6838d20cd9c61",
  "ref" : "refs/heads/main",
  "detector" : {
    "name" : "GitHub Dependency Graph Gradle Plugin",
    "version" : "0.2.0",
    "url" : "https://github.com/gradle/github-dependency-graph-gradle-plugin"
  },
  "manifests" : {
    "dependencies-depend-submit" : {
      "name" : "dependencies-depend-submit",
      "resolved" : { },
      "file" : {
        "source_location" : "settings.gradle"
      }
    }
  },
  "scanned" : "2023-08-25T14:21:33Z"
}

And in case it helps, here is the build.gradle script:

import java.text.SimpleDateFormat

plugins {
    id 'java-library'
    id 'org.openjfx.javafxplugin' version '0.0.13'
}

javafx {
    version = '15'
    modules = ['javafx.base', 'javafx.fxml', 'javafx.controls',
               'javafx.graphics', 'javafx.swing'
    ]
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

configurations {
    extraLibs
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.controlsfx:controlsfx:8.40.12'
    implementation 'org.openjfx:javafx:15.0.1'
    implementation files('dist/Classes.jar')

    extraLibs group: 'org.controlsfx', name: 'controlsfx', version: '8.40.12'

    testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'
    testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.9.3")

    testImplementation 'org.mockito:mockito-core:5.4.0'
    testImplementation 'org.mockito:mockito-junit-jupiter:5.4.0'
}

tasks.withType(Jar).configureEach {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE

    doLast {
        new File("$buildDir/baseVersion.txt").text = gradle.ext.baseVersion
        new File("$buildDir/deployVersion.txt").text = gradle.ext.deployVersion
    }
}

jar {
    compileJava.options.debugOptions.debugLevel = "source,lines,vars"

    //Build MANIFEST.MF
    manifest {
        attributes 'Built-By' : System.properties['user.name']
        attributes 'Build-Timestamp': new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date())
        attributes 'Created-By' : "Gradle ${gradle.gradleVersion}"
        attributes 'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})"
        attributes 'Manifest-Version': gradle.ext.baseVersion
        attributes 'Deploy-Package': gradle.ext.deployVersion
        attributes 'Main-Class': gradle.ext.mainClass
    }

    // Add controlsFX Source Files into JAR output
    from {
        configurations.extraLibs.collect{
            it.isDirectory() ? it: zipTree(it)
        }
    }

    // Set output to dist/App.jar
    archiveBaseName.set("App")
    destinationDirectory.set(file("$rootDir/touchtime/dist"))
}

test {
    useJUnitPlatform()
}

Solution

  • Following @albciff approach, I found that removing the option DEPENDENCY_GRAPH_INCLUDE_CONFIGURATIONS: runtimeClasspath started producing results in the JSON output file. I cannot explain why this was needed for this repo when other repos seem to work, but for now it is producing the dependencies and submitting them to GitHub.