I have project that uses JNI and generates headers for each Java class and have trouble getting the JNI library to rebuild correctly after the headers have been updated. I made a minimal project without both the Java and JNI parts just to illustrate the problem I’m having.
The problem is that even tho the header is changed and the compileMainCpp task recognizes this (with help) the incremental compilation will not pick up the change and recompile the source file.
The build.gradle file I have so far (github project link below):
apply plugin: ‘cpp’
model {
binaries {
all {
cppCompiler.args "-I$buildDir/gen"
}
}
components {
test(NativeExecutableSpec) {
sources {
cpp {
source {
srcDir "."
include "*.cpp"
}
}
}
}
}
}
task generateHeader(type: Copy) {
into "$buildDir/gen"
from(rootProject.file('template.h')) {
rename(/template/, 'generated')
expand([text: 'foo'])
}
}
tasks.all { task ->
def match = task.name =~ /^compile.*Cpp$/
if (match) {
task.dependsOn generateHeader
task.inputs.files project.fileTree(dir: "$buildDir/gen").matching {
include '*.h'
}
}
}
Sample project is available: https://github.com/thejk/gradle-incremental-cpp-generated-header