META-INF/services in JAR with Gradle

后端 未结 5 1877
予麋鹿
予麋鹿 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:50

    If you happen to inherit some ant based legacy code that does not follow the maven conventions, the following may help.

    Define your source sets to match the legacy structure, and include a line like this:

    include 'META-INF/services/**'

    In your source sets. This pattern is generic and will pick up all your meta inf services.

    Full example below.

    sourceSets {
        main {
            java {
                srcDir 'src'
                exclude '**/Test*.java'
            }
            resources {
                srcDir 'src'
                include '**/*.xml'
                include 'META-INF/services/**'
            }
        }
        test {
            java {
                srcDir 'src'
                include '**/Test*.java'
    
            }
            resources { srcDir 'resources' }
        }
    }
    

提交回复
热议问题