简体   繁体   中英

How can I add Gradle managed dependencies to my classpath using SublimeLinter-javac?

I'm trying to set up linting for my Java project. I'm using Sublime Text 3 to code and using Gradle to build from the command line. My problem is I cannot find a way to add dependencies from Gradle to the classpath so that SublimeLinter3 recognizes them. I've tried adding the cache located at ~/.gradle/cache but that didn't seem to work. Is this actually possible or am I trying to do something which can't be done?

Since SublimeLinter-javac underlying use javac to do the linting README ref and linter.py , you can just config the -cp arg to include the classpath directory ( "/gradle/cache/path/*" ).

NOTE, you need to use Java 6 or later to be able to use wildcard option for classpath.

"javac": {
    "lint": "all",
    "args": [
        "-encoding", "UTF8",
         "-cp", "/gradle/cache/path/*",
        "-sourcepath", "${project}/src/"
    ]
}

Let me know if this works.

[UPDATE]

In "Understanding class path wildcards" section of Setting the class path , it detailed as follows (which means the nested folders wont handled):

Subdirectories are not searched recursively. For example, foo/* looks for JAR files only in foo, not in foo/bar, foo/baz, etc.

I ended up having to create 2 separate Gradle tasks: One which gathered my dependencies into one folder and another which built my test jar. This way I could add the folder which had the external dependencies to the classpath and the folder which had my build and test jars (for internal dependency resolutions). Here are the Gradle tasks:

`task copyLibs(type: Copy) {
    from configurations.testRuntime.files
    into "$buildDir/lib"
}
task testJar(type: Jar, dependsOn: testClasses) {
    classifier = 'tests'
    from sourceSets.test.output
}`

After I executed these tasks I was able to add the jars which were created by putting this in my sublime-project file:

"SublimeLinter": {
    "linters": {
        "javac": {
            "lint": "all",
            "args": [
                "-sourcepath", "/home/griff/orch_engine/src/",
                "-cp", "/home/griff/project/build/lib/*:/home/griff/project/build/libs/*"
            ]
        }
    }
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM