2

I am using gradle to build a JNI library for our java project and it works fine, however I can't seem to figure out how to keep gradle from building both shared and static versions of the file. I'd like to disable the build of the static library to speed up the build process. Adding the "shared" tag doesn't seem to do the trick.

From the gradle build file:

libraries {
  bulletjme {
      shared
  }
}

The gradle manual states that "For example, when you define a library called helloworld and build on Linux, Gradle will, by default, produce libhelloworld.so and libhelloworld.a binaries." However it doesn't say how to disable the build of either of the binaries.

Thanks for any answers!

normen
  • 21
  • 3

2 Answers2

3

In Gradle 2.11 this can be set up by setting buildable property to false. Although the documentation says it's read-only, it actually works.

model {
    components {
        library(NativeLibrarySpec) {
            binaries.withType(StaticLibraryBinarySpec) {
                buildable = false
            }
        }
    }
}

When checking components output, Gradle will now say that a library is disabled by user:

$ gradle components
...
Binaries
Shared library 'library:sharedLibrary'
    build using task: :librarySharedLibrary
    build type: build type 'debug'
    flavor: flavor 'default'
    target platform: platform 'linux_x86-64'
    tool chain: Tool chain 'gcc' (GNU GCC)
    shared library file: build/libs/library/shared/liblibrary.so
Static library 'library:staticLibrary' (not buildable)
    build using task: :libraryStaticLibrary
    build type: build type 'debug'
    flavor: flavor 'default'
    target platform: platform 'linux_x86-64'
    tool chain: Tool chain 'gcc' (GNU GCC)
    static library file: build/libs/library/static/liblibrary.a
    Disabled by user

This can also be handled globally for all libraries at once:

model {
    components {
        libraryA(NativeLibrarySpec)
        libraryB(NativeLibrarySpec)
        all {
            binaries.withType(StaticLibraryBinarySpec) {
                buildable = false
            }
        }
    }
}
raspy
  • 3,995
  • 1
  • 14
  • 18
0

To keep gradle from building the static libraries for for the "main" component, you need to have the following code in build.gradle:

model {
    components {
        main(NativeLibrarySpec) {
            sources {
                c {
                    binaries.withType(StaticLibraryBinarySpec) { bin ->
                        binaries.remove(bin)
                    }
                }
            }
        }
    }
}