Quantcast
Channel: Gradle Forums - Latest posts
Viewing all articles
Browse latest Browse all 19859

Java Native Library Task in flat-folder multi-project

$
0
0

I am still very gradle noob so basic principles are eluding me. After I discovered there was nothing in the supplied framework to handle native library declarations in java, I read the docs and forums and found code to do it. I then abstracted a method, resulting in:

def nativeLibraryTask(File nativeSubDir) {
	logger.info('nativeLibraryTask: nativeSubDir={} exists={}', nativeSubDir, nativeSubDir.exists())
	def parentDir = nativeSubDir.getParent()

	repositories {
		flatDir {
			dirs parentDir
		}
	}
	dependencies {
		implementation files(nativeSubDir)
	}
	eclipse {
		classpath {
			file {
				whenMerged {
					def nativeLib = entries.find { it.path.contains nativeSubDir.getName() }
					nativeLib.nativeLibraryLocation = nativeSubDir
				}
			}
		}
	}
}
//todo this works but only when the nativeLibraryTask is defined in the same file
dependencies {
	//todo using project.rootDir.parent because I could not make relative paths between projects work
	nativeLibraryTask(new File(project.rootDir.parent , '<other-project>/<native-lib>'))
}

I would now like to move this method to the master build.gradle so it is available to all sibling projects. However when I do that, the classpath reference is not created. I presume this is a relative file reference issue but have not figured it out yet.

Correction: Logging tells me that the relative file reference is working (the file exists). So here I would like to know how to create a relative path more elegantly using $rootDir or the project reference. But my bigger problem is that the code inside the method is not creating the classpath reference.


Viewing all articles
Browse latest Browse all 19859

Trending Articles