How to switch between mock/non-mock build for safe_app_java/safe-app (not Android)


#1

I am trying to create unit tests for my Java API wrapper for NativeBindings but I am unable to understand how safe-app is getting build. I see the downloading of the native libs and copying files but how do you tell the Intellij IDEA to build mock or non-mock?
@lionel.faber? :slight_smile:


#2

The unit tests for the safe-app module runs only on mock by default.
The magic lies in this custom gradle task :sparkles:

The processTestResources is a default task that runs before running tests. We configure our task as a dependency to copy the mock libs into the required directory. The source folder is ${projectDir}/libs/${platform}/mock/${arch}


#3

I am just curious (not there yet but probably will get in few week(end)s): It is clear for the unit tests, but for a java app - how the switching between mock/non-mock is done? Is there such functionality or it will be developed in the future?


#4

Unfortunately, we haven’t figured that out yet. We’ve been looking into how mock and non-mock dependencies can be managed for desktop platforms. For android the build flavours was very helpful but unfortunately this provision is not available for desktop libraries. Suggestions welcome :slight_smile:


#5

And while we’re in the topic of things we haven’t figured out yet, there’s one more packaging challenge that is on our plate. The platform specific native libraries cannot be conditionally downloaded. We’ve been looking into the packaging process of other java library projects with native code. The most common solution is that they package the native libraries for all platforms together in a single jar which results in increased package size.

We are looking for solutions for these two packaging challenges before we release officially release the desktop libraries on jcenter / maven. If anyone from the community can help us we’re all ears!


#6

While experimenting I have found this plugin: gradle-java-flavours. It provides flavour functionality for java projects but was unable to find how to switch the flavour in Intellij IDEA - it always builds all the flavours.


#7

This is brilliant! I’ll give it a shot! Thanks :slight_smile:

The flavour switching feature in IntelliJ shows up only for android projects. I’ll play around and see how we can have flavour specific builds with some gradle goodness!

Thanks again! :heart:


#8

We’ve applied this plugin in the project and it has helped improve the build script a lot. Perhaps the new structure can help you out too :slight_smile:

I didn’t get around to getting the flavours to turn up on IntelliJ but gradle safe-app:tasks will display a list of flavour-specific tasks prefixed by mock or nonMock