gradleclasspathbuild-script

Gradle: use wildcard in jar name in classpath


Gradle: use wildcard in jar name in classpath

buildscript {
    repositories {
        flatDir {
            dirs "foo/lib"
        }
    }

    dependencies {
        classpath name: 'bar-*-util'
    }
}

The bar version can be any version such as bar-1.0-util.jar, bar-2.0-util.jar


Solution

  • You can try to add all the jars you have in a lib directory as follows:

    dependencies {
        classpath fileTree(dir: 'foo/lib', include: ['*.jar'])
    }
    

    or just specific jars as:

    classpath fileTree(dir: 'foo/lib', include: ['bar-*-util.jar'])
    

    And you don't need to specify a flatDir repository in that case.