Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Gradle adding a classpath entry

I'm adding a classpath entry to the .classpath file in Eclipse to avoid having to add it manually each time I run the .eclipse task while I add a number of dependencies. I need some resources on the path to run locally.

this works,

eclipse.classpath.file {
   withXml { 
     def node = it.asNode()
     node.appendNode('classpathentry', 
                [kind: 'lib', path: '/some/path'])
           }
}

this doesn't,

eclipse.classpath.file {
   whenMerged { classpath ->
      classpath.entries.add { entry -> kind: 'lib', path: '/some/path' }
              }
}

The error I get is,

startup failed: build.gradle': 75: unexpected token: lib @ line 75, column 48. .entries.add { entry -> kind: 'lib', pat ^

For future reference, what is wrong with the second example?

like image 223
Neill Avatar asked Mar 19 '26 02:03

Neill


1 Answers

The equivalent should be something like:

eclipse.classpath.file {
  whenMerged { classpath ->
    def lib = new org.gradle.plugins.ide.eclipse.model.Library(fileReference(file('path/to/my/jar')))
    lib.exported = true
    classpath.entries << lib
  }
}

See Gradle docs for Library and its interface ClasspathEntry.

like image 194
Markus Pscheidt Avatar answered Mar 21 '26 14:03

Markus Pscheidt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!