Eclipse not handling absolute URL file in when used to specify dependency

(sebtardif) #1

Absolute Windows file URL not handled correctly.

I have this URL, which is recognized by Internet Explorer -> file:///C:/svnRepo/trunk/tmp-workdir-quantcommons/quantcommons-20130925110051.jar

Then when I used it for a dependency in build.gradle using -> files(‘file:///C:/svnRepo/trunk/tmp-workdir-quantcommons/quantcommons-20130925110051.jar’)

I get the following error in the Eclipse Problems tab -> The container ‘Gradle Dependencies’ references non existing library ‘C:\svnRepo\trunk\ReferenceData\svnRepo\trunk\tmp-workdir-quantcommons\quantcommons-20130925110051.jar’

I uses Gradle 1.7, the problem happen only when doing the build in Eclipse and work fine in command line. I use latest STS release, based on Kepler Eclipse.

(Peter Niederwieser) #2

The ‘files’ method only accepts (relative or absolute) file paths, but not file URLs.

(sebtardif) #3

Fair enough. So it works by accident in the command line and it’s understood that Eclipse could fail (and do fail).

But, if I do the following I get the same exact behavior -> files(file(‘file:///C:/svnRepo/trunk/tmp-workdir-quantcommons/quantcommons-20130925110051.jar’))

Then I can see from an example passing “file” in “files” -> FileCollection collection = files(‘src/file1.txt’, new File(‘src/file2.txt’), [‘src/file3.txt’, ‘src/file4.txt’])

Also from same URL we can read -> The file() method also understands URLs, such as file:/some/path.xml.

Well, the all thing is not clear at all. I know you guys are executing the examples in the documentation, so it will be appreciated you add to the examples how to specify an absolute Windows path in a dependency.

(Peter Niederwieser) #4

You are right; Strings containing file URLs are said to be supported. At first sight, it appears that Gradle interprets your URL as a relative rather than absolute path. I’ve raised GRADLE-2897 for this. Meanwhile, you may want to use a file path instead. (Why are you using an URL?)

(Dimitry K) #5

As I just begin to use gradle, I have spent couple of days trying to find a way to specify absolute path (on Windows).

So here’s my little code showing how to include local jar on local machine by specifying local path. There’re two options (uncomment the one you prefer) showing how to specify jar with version name and just regular jar name.

Hope this saves time for someone:

apply plugin: 'java'
  repositories {
   flatDir(dirs: 'd:/wamp/www/javalib/11November/DimutilsSrc/build/libs/')
  dependencies {
 compile 'mysql:mysql-connector-java:5.1.26'
 compile 'log4j:log4j:1.2.17'
 compile 'org.twitter4j:twitter4j-core:3.0.5'
 compile 'org.twitter4j:twitter4j-stream:3.0.5'
        testCompile group: 'junit', name: 'junit', version: '3.+'
                  // option 1 (jar without version numbers)
        compile name: 'DimUtilsSrc'
        // if you leave this line
        // it would load file
        // d:\wamp\www\javalib1November\DimutilsSrc\build\libs\DimutilsSrc.jar
      // option 2 (jar WITH version numbers)
      compile ':DimUtilsSrc:0.1'
      // if you leave this line
      // this would load file
      // d:\wamp\www\javalib1November\DimutilsSrc\build\libs\DimutilsSrc-0.1.jar

(ps. and yes, I know that specifying absolute path to the local jar is bad practise, but this is just my first steps with gradle)

pps. it looks a bit messy because of the line wraps, but if you copy/paste it to text editor, it will look neat and simple.