wpilibsuite / gradle-jni

Gradle plugin for ease of creating JNI libraries.
14 stars 5 forks source link

minimal example project fails with "No such property: JniNativeLibrarySpec for class: org.gradle.model.ModelMap" #5

Closed liblit closed 6 years ago

liblit commented 6 years ago

I created a minimal example project in which to experiment with the Gradle JNI plugin. Unfortunately, native compilation tasks such as components or model fail due to some problem resolving JniNativeLibrarySpec. For example, ./gradlew model reports:

FAILURE: Build failed with an exception.

* Where:
Build file '/nobackup/liblit/joust/simple-jni/build.gradle' line: 9

* What went wrong:
Execution failed for task ':model'.
> Exception thrown while executing model rule: components { ... } @ build.gradle line 8, column 3
   > No such property: JniNativeLibrarySpec for class: org.gradle.model.ModelMap

Note: the JNI pluginʼs instructions refer to version '0.1.6', but the latest version available from the main Gradle plugins repository is version 0.1.5, so the latter is what my minimal example project uses. Perhaps that version mismatch is the cause of the problem? Should JniNativeLibrarySpec exist in release 0.1.5, or was that not added until later? Should a newer plugin release be made available in the official Gradle plugins repository?

Also on the topic of versions, I am using the latest official Gradle release: version 4.7. Is this plugin known to work with Gradle 4.7?

For the record, I am aware that my minimal example project is actually incomplete: it declares a native method but provides no native implementation thereof. That is OK for now. I am learning as I go, and wanted to start with simply declaring the native model as per the JNI pluginʼs instructions.

ThadHouse commented 6 years ago

You need to apply the cpp plugin as well.

ThadHouse commented 6 years ago

Basically, the standard Gradle plugin style recommends not directly applying external project, and instead depending on the users applying themselves.

liblit commented 6 years ago

Thanks for the speedy reply, @ThadHouse. Unfortunately, adding apply plugin: 'cpp' did not help, or at least was not sufficient. Model-related tasks still fail as before.

ThadHouse commented 6 years ago

Ok. I didn't realize I hadn't pushed the update that fixed that bug.

I pushed update 0.2.1. Also, I would recommend declaring all of your plugins like below, rather then the way you had it.

plugins {
  id 'edu.wpi.first.GradleJni' version '0.2.1'
  id 'application'
  id 'cpp'
}
liblit commented 6 years ago

Plugin version 0.2.1 fixed this problem. Excellent! Thank you for your super-speedy help, @ThadHouse.

Thanks as well for the style advice on loading plugins. I have become the main build system wrangler for WALA, a large Java research project. This is the same project in which I hope to eventually put your Gradle JNI plugin to real use. WALA has roughly 1,300 lines of Gradle build infrastructure, and I learned most of whatʼs in there by trial and error. The native compilation parts were especially tricky to figure out. I expect there are many things that I could be doing better if I knew more about idiomatic Gradle style. Of course, if someone with more Gradle experience wanted to look at what we are doing in WALA, and maybe contribute pull requests for any Gradle improvements, I know that the WALA maintainers are very welcoming to outside contributors.... :wink: