How can I prevent shared lib building in Gradle? I only want static libs

I have a pretty standard build.gradle with 2 libraries defined. I only want to build static versions of the libraries when I do an “assemble”.

sources

{

main

{

cpp

{

libraries.LibSqLite3.static

libraries.LibFileIO.static

}

} }

I tell it the libs are static but, it still tries to build the DLL’s.

Your syntax isn’t right for declaring dependencies:

executables {
  main
}
sources {
  main {
    cpp {
      lib libraries.LibSqLite3.static
    }
  }
}

Then if you build the mainExecutable (‘gradle mainExecutable’), only the required variants of the libraries will be built.

Thanks. That does work.

There’s no way in the gradle file I can force it to not build build shared libs if I do an assemble? I’d like it if they didn’t even show up in the task list. Being able to rebuild everything with a single command would come in handy. I have X86, X64 and Arm variants I want to build.

There’s no nice way to do this yet. Depending on the Gradle version you’re using, you might be able to do:

binaries.withType(SharedLibraryBinary) { binary ->
    buildable = false
}

Then ‘assemble’ should not build the shared libs.

That worked like a champ. Now “Assemble” just builds my static libs in all variants.

Thanks again.

Something I can work around but, you might want to know about.

expat-2.1.0

is the folder name for one of my libs. Gradle doesn’t like the .0 in the path at all.

* What went wrong:
Could not compile build file 'Z:\Work\build.gradle'.
> startup failed:
  build file 'Z:\Work\build.gradle': 8: unexpected token: 0 @ line 8, column 12.
        expat-2.1.0 {}
                ^

Hi there,

is it also possible to define just a specific project not to generate a shared library? So by default saying don’t build any shared libs except for project A?

Thanks, Martin

Yes, as mentioned above you can set the ‘buildable’ flag to false for any binaries you don’t want to build. To enable building for a specific component, try this (untested):

binaries.withType(SharedLibraryBinary) {
    buildable = false
}
libraries {
    projectAlib {
        binaries.withType(SharedLibraryBinary) {
             buildable = true
        }
    }
}