Use Java class in Gradle build script

前端 未结 1 1242
醉话见心
醉话见心 2020-12-19 08:15

I have a Gradle build script which has to instantiate a Java class in a Task and call a method on the created object. Currently, I have the following:

apply          


        
相关标签:
1条回答
  • 2020-12-19 08:51

    The dependency compile files("libs/some.library.jar") is added as a project dependency not as the script dependency itself. What You need to do is to add this dependency in script's classpath scope.

    apply plugin: 'java'
    
    buildscript {
       dependencies {
          classpath files("libs/some.library.jar")
       }
    }
    
    task A << {
        def obj = new some.library.TestClass()
        obj.doSomething()
    }
    

    Now it should work.

    0 讨论(0)
提交回复
热议问题