Skip to content

Scan not performed on saved ClassGraph object #398

@cdprete

Description

@cdprete

Hi.
I don't understand why the scanning is not performed if I store the ClassGraph instance in a variable before calling the scan() method.

For example:

class MyMavenRunner{
    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
            val parsedArgs = parseCommandArgs(args)
            val classGraph =
                    ClassGraph()
                            .verbose()
                            .enableClassInfo()
                            .enableMethodInfo()
                            .disableJarScanning()
                            .disableNestedJarScanning()
                            .whitelistPackages(BASE_PACKAGE)
                            .overrideClasspath(parsedArgs.projectBuildPath.toString())

            val data= generateData(classGraph)
            print(data)
        }
    }
}

(where generateData(ClassGraph), declared in another class as static, calls inside classGraph.scan().use {...}) doesn't work (I get 2020-02-04T11:35:35.667+0100 ClassGraph Only returning classpath elements (not performing a scan) from the verbose(), which causes then an NPE when I call getClassesImplementing(MyClass.class.canonicalName)), but if I do

ClassGraph()
                            .verbose()
                            .enableClassInfo()
                            .enableMethodInfo()
                            .disableJarScanning()
                            .disableNestedJarScanning()
                            .whitelistPackages(BASE_PACKAGE)
                            .overrideClasspath(parsedArgs.projectBuildPath.toString())
                            .scan()
                            .use { scanResult -> ... }

inside the generateData directly it works fine.

The main(args) is called from the Maven Exec Plugin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions