peez80
peez80

Reputation: 1643

Displaying local file dependencies

I created a small test build file to analyze a behavior I just discovered and I am not sure if it's a mistake by me or standard gradle behavior.

I'm just starting migrating an old ant project to gradle. The first step would be to copy all jar files locally and create a local file dependency. I tried to check the dependency declaration but with gradle dependenciesthey won't show up.

I created a small test gradle script:

apply plugin: 'java'

repositories {
    jcenter()
}

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.7'

    //compile fileTree('tmp_libs')
    compile files('tmp_libs/hsqldb/hsqldb_2.2.8.jar')

    testCompile 'junit:junit:4.12'
}

When running gradle dependencies I can see the slf4j dependency but not the hsqldb dependency. Am I doing anything wrong or is it just normal gradle behaviour to not show local file dependencies? Is there some other way to check if the dependency declarations are working?

Upvotes: 4

Views: 197

Answers (1)

frhd
frhd

Reputation: 10244

It seems that gradle dependencies will not be able to retrieve the dependency tree information from locally added jars.

However, if you're using IntelliJ IDEA or Ecplise, you will see them in the build path after building it with gradle idea or gradle eclipse, respectively.

Another way to see if your dependency declarations are working would be to output the classpath through gradle. You could use a task like this:

task printClasspath << {
  (configurations.runtime.asPath =~ /(?<jar>[^:]+)/).each {match, jar ->
    println jar
  }
}

When calling it with gradle printClasspath (or short with gradle pC in the later versions), this task will "pretty print" the classpath with the help of a regex, which finds all entries separated by a colon.

Upvotes: 4

Related Questions