META-INF/services in JAR with Gradle

后端 未结 5 1882
予麋鹿
予麋鹿 2020-12-14 07:06

I wanted to build a plugin module that can be loaded with a ServiceLoader. This requires adding a file to the META-INF/services directory, that is named after t

5条回答
  •  醉话见心
    2020-12-14 07:24

    Meanwhile I found a solution to my problem in a (somewhat) similar Question.

    Adding the following to the gradle.build file, resolves my problem

    jar {
      from ('./src/main/java') {
        include 'META-INF/services/org.example.plugins.PluginService'
      }
    }
    

    Now the JAR file looks as expected

    .
    |- org
    |  `- example
    |     `- plugins
    |        `- impl
    |           `- ExamplePlugin.class
    `- META-INF
       |- MANIFEST.MF
       `- services
          `- org.example.plugins.PluginService
    

提交回复
热议问题