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

Java Native Library Task in flat-folder multi-project

$
0
0

Apologies for thinking I was ready to share the problem but then finding out more with further investigation. Once some logging issues were fixed, I got further.

The string escaping problem was solved by learning the difference between "{foo}" and '{foo}’.

$rootDir refers to the master project and not the current project (the one calling the method). So "$rootDir/<other-project>/<native-lib>" becomes "<absolute-path-to-parent-folder>/master/<other-project>/<native-lib>" instead of the correct "<absolute-path-to-parent-folder>/<other-project>/<native-lib>". (“master” should not be in the path.)

The problem with moving nativeLibraryTask to the master build.gradle is that it operates on the master project instead of the current project. So it adds the native path to the master project instead of the current project. I did not expect that. So now I need to change the code to either pass the current project to nativeLibraryTask as an argument or figure out how to make a task inside a method refer to the calling project instead of the project of the file it is defined in.

The following works. In the master build.gradle file:

def nativeLibraryTask(Project callingProject, String relPath) {
	File nativeSubDir = new File(callingProject.rootDir.parent, relPath)
	if (!nativeSubDir.exists()) {
		logger.error('nativeLibraryTask: nativeSubDir={} does not exist', nativeSubDir)
		return
	}
	def parentDir = nativeSubDir.getParent()

	callingProject.repositories {
		flatDir {
			dir parentDir
		}
	}
	callingProject.dependencies {
		implementation files(nativeSubDir)
	}
	callingProject.eclipse {
		classpath {
			file {
				whenMerged {
					def nativeLib = entries.find { it.path.contains nativeSubDir.getName() }
					nativeLib.nativeLibraryLocation = nativeSubDir
				}
			}
		}
	}
}

And in the subproject build.gradle file:

dependencies {	
	nativeLibraryTask(project, '<other-project>/<native-lib>')
}

Any improvements welcome.


Viewing all articles
Browse latest Browse all 20335

Trending Articles