{"id":15043516,"url":"https://github.com/bytedeco/gradle-javacpp","last_synced_at":"2025-04-06T09:10:27.668Z","repository":{"id":42993971,"uuid":"265488490","full_name":"bytedeco/gradle-javacpp","owner":"bytedeco","description":"Gradle plugins to automate the build process of JavaCPP and JavaCV","archived":false,"fork":false,"pushed_at":"2025-02-11T00:57:07.000Z","size":88,"stargazers_count":59,"open_issues_count":4,"forks_count":21,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T08:10:33.314Z","etag":null,"topics":["c","c-plus-plus","cpp","gradle","gradle-plugin","java","javacpp","javacv","jni","opencv","opencv-java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bytedeco.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-20T07:40:27.000Z","updated_at":"2025-02-20T09:24:22.000Z","dependencies_parsed_at":"2023-01-30T03:45:53.747Z","dependency_job_id":"83483efb-4b45-46c9-a901-114c491ea4a7","html_url":"https://github.com/bytedeco/gradle-javacpp","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytedeco%2Fgradle-javacpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytedeco%2Fgradle-javacpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytedeco%2Fgradle-javacpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytedeco%2Fgradle-javacpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bytedeco","download_url":"https://codeload.github.com/bytedeco/gradle-javacpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457803,"owners_count":20941906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c-plus-plus","cpp","gradle","gradle-plugin","java","javacpp","javacv","jni","opencv","opencv-java"],"created_at":"2024-09-24T20:49:12.632Z","updated_at":"2025-04-06T09:10:27.646Z","avatar_url":"https://github.com/bytedeco.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Gradle JavaCPP\r\n==============\r\n\r\n[![Gitter](https://badges.gitter.im/bytedeco/javacpp.svg)](https://gitter.im/bytedeco/javacpp) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.bytedeco/gradle-javacpp/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.bytedeco/gradle-javacpp) [![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/org.bytedeco/gradle-javacpp.svg)](http://bytedeco.org/builds/) [![Build Status](https://travis-ci.org/bytedeco/gradle-javacpp.svg?branch=master)](https://travis-ci.org/bytedeco/gradle-javacpp) \u003csup\u003eCommercial support:\u003c/sup\u003e [![xscode](https://img.shields.io/badge/Available%20on-xs%3Acode-blue?style=?style=plastic\u0026logo=appveyor\u0026logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////////VXz1bAAAAAJ0Uk5T/wDltzBKAAAAlUlEQVR42uzXSwqAMAwE0Mn9L+3Ggtgkk35QwcnSJo9S+yGwM9DCooCbgn4YrJ4CIPUcQF7/XSBbx2TEz4sAZ2q1RAECBAiYBlCtvwN+KiYAlG7UDGj59MViT9hOwEqAhYCtAsUZvL6I6W8c2wcbd+LIWSCHSTeSAAECngN4xxIDSK9f4B9t377Wd7H5Nt7/Xz8eAgwAvesLRjYYPuUAAAAASUVORK5CYII=)](https://xscode.com/bytedeco/gradle-javacpp)\r\n\r\n\r\nIntroduction\r\n------------\r\nGradle JavaCPP offers plugins that make it easy to use [JavaCPP](https://github.com/bytedeco/javacpp) and [JavaCV](https://github.com/bytedeco/javacv) as part of the Gradle build system.\r\n\r\nPlease feel free to ask questions on [the mailing list](http://groups.google.com/group/javacpp-project) if you encounter any problems with the software! I am sure it is far from perfect...\r\n\r\n\r\nRequired Software\r\n-----------------\r\nTo use Gradle JavaCPP, you will need to download and install the following software:\r\n\r\n * An implementation of Java SE 8 or newer:\r\n   * OpenJDK  http://openjdk.java.net/install/  or\r\n   * Oracle JDK  http://www.oracle.com/technetwork/java/javase/downloads/  or\r\n   * IBM JDK  http://www.ibm.com/developerworks/java/jdk/\r\n * Gradle 6.0 or newer: https://gradle.org/releases/\r\n\r\n\r\nGetting Started\r\n---------------\r\nGradle JavaCPP comes with 2 plugins:\r\n\r\n * [The build plugin](#the-build-plugin) to create new packages containing native libraries using JavaCPP, and\r\n * [The platform plugin](#the-platform-plugin) to select from existing artifacts the ones corresponding to user-specified platforms.\r\n\r\nFully functional sample projects are also provided in the [`samples`](samples) subdirectory and can be used as templates.\r\n\r\n\r\n### The Build Plugin\r\nTo understand how [JavaCPP](https://github.com/bytedeco/javacpp) is meant to be used, one should first take a look at the [Mapping Recipes for C/C++ Libraries](https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes), but a high-level overview of the [Basic Architecture](https://github.com/bytedeco/javacpp/wiki/Basic-Architecture) is also available to understand the bigger picture.\r\n\r\nOnce comfortable enough with the command line interface, the build plugin for Gradle can be used to integrate easily that workflow as part of `build.gradle` as shown below. By default, for Java libraries and applications, it creates a `javacppJar` task that archives the native libraries into a separate JAR file and sets its classifier to `$javacppPlatform$javacppPlatformExtension`, while excluding those files from the default `jar` task. To customize the behavior, there are properties that can be modified and whose documentation is available as part of the source code in these files:\r\n\r\n * [`BuildTask.java`](src/main/java/org/bytedeco/gradle/javacpp/BuildTask.java)\r\n * [`BuildPlugin.java`](src/main/java/org/bytedeco/gradle/javacpp/BuildPlugin.java)\r\n * [`BuildExtension.java`](src/main/java/org/bytedeco/gradle/javacpp/BuildExtension.java)\r\n\r\n```groovy\r\nplugins {\r\n    id 'java-library'\r\n    id 'org.bytedeco.gradle-javacpp-build' version \"$javacppVersion\"\r\n}\r\n\r\n// We can set this on the command line too this way: -PjavacppPlatform=android-arm64\r\next {\r\n    javacppPlatform = 'android-arm64' // or any other platform, defaults to Loader.getPlatform()\r\n}\r\n\r\ndependencies {\r\n    api \"org.bytedeco:javacpp:$javacppVersion\"\r\n}\r\n\r\ntasks.withType(org.bytedeco.gradle.javacpp.BuildTask) {\r\n    // set here default values for all build tasks below, typically just includePath and linkPath,\r\n    // but also properties to set the path to the NDK and its compiler in the case of Android\r\n}\r\n\r\njavacppBuildCommand {\r\n    // typically set here the buildCommand to the script that fills up includePath and linkPath\r\n}\r\n\r\njavacppBuildParser {\r\n    // typically set here the classOrPackageNames to class names implementing InfoMap\r\n}\r\n\r\njavacppBuildCompiler {\r\n    // typically set here boolean flags like copyLibs\r\n}\r\n```\r\n\r\n\r\n#### Integration with Android Studio\r\n\r\nIt is also possible to integrate the `BuildTask` with Android Studio for projects with C/C++ support by:\r\n\r\n 1. Following the instructions at https://developer.android.com/studio/projects/add-native-code ,\r\n 2. Adding something like below to the `app/build.gradle` file, and\r\n```groovy\r\nandroid.applicationVariants.all { variant -\u003e\r\n    def variantName = variant.name.capitalize() // either \"Debug\" or \"Release\"\r\n    def javaCompile = project.tasks.getByName(\"compile${variantName}JavaWithJavac\")\r\n    def configureCMake = project.tasks.findAll {\r\n        it.name.startsWith(\"configureCMake$variantName\")\r\n    }\r\n\r\n    // Compiles NativeLibraryConfig.java\r\n    task \"javacppCompileJava$variantName\"(type: JavaCompile) {\r\n        include 'com/example/myapplication/NativeLibraryConfig.java'\r\n        source = javaCompile.source\r\n        classpath = javaCompile.classpath\r\n        destinationDir = javaCompile.destinationDir\r\n    }\r\n\r\n    // Parses NativeLibrary.h and outputs NativeLibrary.java\r\n    task \"javacppBuildParser$variantName\"(type: org.bytedeco.gradle.javacpp.BuildTask) {\r\n        dependsOn \"javacppCompileJava$variantName\"\r\n        classPath = [javaCompile.destinationDir]\r\n        includePath =  [\"$projectDir/src/main/cpp/\"]\r\n        classOrPackageNames = ['com.example.myapplication.NativeLibraryConfig']\r\n        outputDirectory = file(\"$projectDir/src/main/java/\")\r\n    }\r\n\r\n    // Compiles NativeLibrary.java and everything else\r\n    javaCompile.dependsOn \"javacppBuildParser$variantName\"\r\n\r\n    // Generates jnijavacpp.cpp and jniNativeLibrary.cpp\r\n    task \"javacppBuildCompiler$variantName\"(type: org.bytedeco.gradle.javacpp.BuildTask) {\r\n        dependsOn javaCompile\r\n        classPath = [javaCompile.destinationDir]\r\n        classOrPackageNames = ['com.example.myapplication.NativeLibrary']\r\n        compile = false\r\n        deleteJniFiles = false\r\n        outputDirectory = file(\"$projectDir/src/main/cpp/\")\r\n    }\r\n\r\n    // Picks up the C++ files listed in CMakeLists.txt\r\n    configureCMake.forEach {\r\n        it.dependsOn \"javacppBuildCompiler$variantName\"\r\n    }\r\n}\r\n```\r\n 3. Updating the `CMakeLists.txt` file to include the generated `.cpp` files.\r\n\r\n\r\n### The Platform Plugin\r\nWith Maven, we are able to modify dependencies transitively using profiles, and although Gradle doesn't provide such functionality out of the box, it can be emulated via plugins. After adding a single line to the `build.gradle` script as shown below, the platform plugin will filter the dependencies of artifacts whose names contain \"-platform\" using the comma-separated values given in `$javacppPlatform`. To understand better how this works, it may be worth taking a look at the source code of the plugin:\r\n\r\n * [`PlatformRule.java`](src/main/java/org/bytedeco/gradle/javacpp/PlatformRule.java)\r\n * [`PlatformPlugin.java`](src/main/java/org/bytedeco/gradle/javacpp/PlatformPlugin.java)\r\n\r\n```groovy\r\nplugins {\r\n    id 'java-library'\r\n    id 'org.bytedeco.gradle-javacpp-platform' version \"$javacppVersion\"\r\n}\r\n\r\n// We can set this on the command line too this way: -PjavacppPlatform=linux-x86_64,macosx-x86_64,windows-x86_64,etc\r\next {\r\n    javacppPlatform = 'linux-x86_64,macosx-x86_64,windows-x86_64,etc' // defaults to Loader.getPlatform()\r\n}\r\n\r\ndependencies {\r\n    api \"org.bytedeco:javacv-platform:$javacvVersion\" // or any other \"-platform\" artifacts\r\n}\r\n```\r\n\r\nMoreover, in the case of Android, its plugin is not able to use native libraries found in JAR files when building Android App Bundles (AAB files). However, to work around this limitation we can easily use Gradle to extract the files automatically, for example, in the following manner with an additional `javacppExtract` task inside `app/build.gradle`:\r\n\r\n```groovy\r\nconfigurations {\r\n    javacpp\r\n}\r\n\r\ntask javacppExtract(type: Copy) {\r\n    dependsOn configurations.javacpp\r\n\r\n    from { configurations.javacpp.collect { zipTree(it) } }\r\n    include \"lib/**\"\r\n    into \"$buildDir/javacpp/\"\r\n    android.sourceSets.main.jniLibs.srcDirs += [\"$buildDir/javacpp/lib/\"]\r\n\r\n    tasks.getByName('preBuild').dependsOn javacppExtract\r\n}\r\n\r\ndependencies {\r\n    implementation group: 'org.bytedeco', name: 'javacv', version: \"$javacvVersion\"\r\n    javacpp group: 'org.bytedeco', name: 'openblas-platform', version: \"$openblasVersion-$javacppVersion\"\r\n    javacpp group: 'org.bytedeco', name: 'opencv-platform', version: \"$opencvVersion-$javacppVersion\"\r\n    javacpp group: 'org.bytedeco', name: 'ffmpeg-platform', version: \"$ffmpegVersion-$javacppVersion\"\r\n    ...\r\n}\r\n```\r\n\r\n\r\n----\r\nProject lead: Samuel Audet [samuel.audet `at` gmail.com](mailto:samuel.audet\u0026nbsp;at\u0026nbsp;gmail.com)  \r\nDeveloper site: https://github.com/bytedeco/gradle-javacpp  \r\nDiscussion group: http://groups.google.com/group/javacpp-project\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytedeco%2Fgradle-javacpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytedeco%2Fgradle-javacpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytedeco%2Fgradle-javacpp/lists"}