简体   繁体   中英

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?

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 .

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