Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jnigen] standardize on using gradle to build all artifacts versus a mix of Maven and Gradle #1948

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c3357b4
Migrate build summarizer build to gradle wrapper
jwill Jan 22, 2025
b14ce38
Add required gradle wrapper files
jwill Jan 22, 2025
243c2a4
Make build summarizer generate a jar with all the dependencies
jwill Jan 23, 2025
e3e93d0
Add Gradle Tools class, changes to Maven Tools
jwill Jan 23, 2025
5b3bc6a
Update generate.dart
jwill Jan 23, 2025
8d2a4c5
Integrate GradleTools in Summary
jwill Jan 23, 2025
df055d5
Call appropriate executable on Windows platform.
jwill Jan 23, 2025
aa055e7
Ignore .gradle directory in calculating staleness
jwill Jan 24, 2025
b4ca6d7
Housekeeping
jwill Jan 24, 2025
41a8f5a
Remove references to MavenTools
jwill Jan 24, 2025
d0fc242
Update android_sdk_tools.dart
jwill Jan 24, 2025
1b0ea63
Merge branch 'dart-lang:main' into jnigen-gradle
jwill Jan 24, 2025
2cc5ab7
Removing logging
jwill Jan 24, 2025
27c20e3
Merge branch 'jnigen-gradle' of https://github.com/jwill/native into …
jwill Jan 24, 2025
71cbe62
Bump kotlin android plugin to 1.8.10
jwill Jan 28, 2025
375550d
Merge branch 'dart-lang:main' into jnigen-gradle
jwill Jan 28, 2025
03e55e5
Merge branch 'dart-lang:main' into jnigen-gradle
jwill Jan 28, 2025
042548c
Remove maven_tools.dart
jwill Jan 29, 2025
db91748
Nits and whitespace
jwill Jan 29, 2025
5c6d4e7
Move jni to use gradle wrapper
jwill Jan 29, 2025
40db0f8
Merge branch 'jnigen-gradle' of https://github.com/jwill/native into …
jwill Jan 29, 2025
f0f694f
Adding previously excluded gradlew files to jni
jwill Jan 30, 2025
18c2cb8
Remove maven from kotlin_test
jwill Jan 30, 2025
fb07665
Delete pom.xml
jwill Jan 30, 2025
72cab2a
Merge branch 'main' into jnigen-gradle
HosseinYousefi Feb 3, 2025
6cf76f1
[jni] Dart format, update CHANGELOG, bump minor version.
jwill Feb 4, 2025
f29d5d5
[jnigen] Move `bindings_test_setup.dart` to gradle from mvn
jwill Feb 4, 2025
51321c7
dart format updates
jwill Feb 4, 2025
0f7cae2
dart fix
jwill Feb 4, 2025
4155f43
Update setup.dart
jwill Feb 4, 2025
b91f7e0
Update setup.dart
jwill Feb 5, 2025
18a07f1
Merge branch 'main' into jnigen-gradle
HosseinYousefi Feb 5, 2025
033ed11
Update summary.dart
jwill Feb 5, 2025
8648360
Update find_package.dart
jwill Feb 5, 2025
1d6a387
Added place holder pom.xml for instance setup
jwill Feb 6, 2025
2c800c8
Merge branch 'dart-lang:main' into jnigen-gradle
jwill Feb 6, 2025
ab76939
Housekeeping to merge `Operators` changes from main
jwill Feb 6, 2025
32a3c7e
Merge branch 'jnigen-gradle' of https://github.com/jwill/native into …
jwill Feb 6, 2025
7984cda
Re-added downloading discrete source jars
jwill Feb 6, 2025
8c6f169
Add target path property to jni gradle and allow specifiying from com…
jwill Feb 7, 2025
9974029
Quiet gradle messages
jwill Feb 7, 2025
0e35451
flutter analyze fixes
jwill Feb 7, 2025
ea8fe7a
get transitive dependencies for source jars
jwill Feb 7, 2025
a1bb6af
Update build_summarizer.dart
jwill Feb 7, 2025
5d30ddb
Update build_summarizer.dart
jwill Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkgs/jni/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.14.1
- Moved build system for Java code from Maven to Gradle.
- Updated `bin\setup.dart` to do lookup for a Gradle wrapper executable.
- Change eliminates the need to install Maven, all that is
needed is a Java install.

## 0.14.0

- Added `DynamicLibraryLoadError` which is thrown when the dynamic library fails
Expand Down
84 changes: 59 additions & 25 deletions pkgs/jni/bin/setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const _verbose = 'verbose';
const _cmakeArgs = 'cmake-args';

Future<void> runCommand(
String exec, List<String> args, String workingDir) async {
String exec,
List<String> args,
String workingDir,
) async {
// For printing relative path always.
var current = Directory.current.path;
if (!current.endsWith(Platform.pathSeparator)) {
Expand All @@ -37,7 +40,8 @@ Future<void> runCommand(
int status;
if (options.verbose) {
final process = await Process.start(
exec, args,
exec,
args,
workingDirectory: workingDir,
mode: ProcessStartMode.inheritStdio,
// without `runInShell`, sometimes cmake doesn't run on windows.
Expand All @@ -49,8 +53,12 @@ Future<void> runCommand(
}
} else {
// ProcessStartMode.normal sometimes hangs on windows. No idea why.
final process = await Process.run(exec, args,
runInShell: true, workingDirectory: workingDir);
final process = await Process.run(
exec,
args,
runInShell: true,
workingDirectory: workingDir,
);
status = process.exitCode;
if (status != 0) {
exitCode = status;
Expand Down Expand Up @@ -144,17 +152,28 @@ String getTargetName(Directory cDir) {

void main(List<String> arguments) async {
final parser = ArgParser()
..addOption(_buildPath,
abbr: 'b', help: 'Directory to place built artifacts')
..addMultiOption(_srcPath,
abbr: 's', help: 'alternative path to package:jni sources')
..addMultiOption(_packageName,
abbr: 'p',
help: 'package for which native'
'library should be built')
..addOption(
_buildPath,
abbr: 'b',
help: 'Directory to place built artifacts',
)
..addMultiOption(
_srcPath,
abbr: 's',
help: 'alternative path to package:jni sources',
)
..addMultiOption(
_packageName,
abbr: 'p',
help: 'package for which native'
'library should be built',
)
..addFlag(_verbose, abbr: 'v', help: 'Enable verbose output')
..addMultiOption(_cmakeArgs,
abbr: 'm', help: 'Pass additional argument to CMake');
..addMultiOption(
_cmakeArgs,
abbr: 'm',
help: 'Pass additional argument to CMake',
);
final argResults = parser.parse(arguments);
options = Options(argResults);
final rest = argResults.rest;
Expand All @@ -174,8 +193,10 @@ void main(List<String> arguments) async {
}
if (sources.isEmpty) {
final dependencySources = await findDependencySources();
stderr.writeln('selecting source directories for dependencies: '
'${dependencySources.keys}');
stderr.writeln(
'selecting source directories for dependencies: '
'${dependencySources.keys}',
);
sources.addAll(dependencySources.values);
} else {
stderr.writeln('selecting source directories: $sources');
Expand All @@ -194,17 +215,28 @@ void main(List<String> arguments) async {

final javaSrc = await findSources('jni', 'java');
final targetJar = File.fromUri(buildDir.uri.resolve('jni.jar'));
final isWin = Platform.isWindows;
verboseLog('File exists:${targetJar.existsSync()}');

final gradleWExecutable = (Platform.isLinux || Platform.isMacOS)
? Uri.directory(javaSrc).resolve('gradlew')
: Uri.directory(javaSrc).resolve('gradlew.bat');

if (!needsBuild(targetJar, Directory.fromUri(Uri.directory(javaSrc)))) {
verboseLog('Last modified of ${targetJar.path}: '
'${targetJar.lastModifiedSync()}.');
verboseLog(
'Last modified of ${targetJar.path}: '
'${targetJar.lastModifiedSync()}.',
);
stderr.writeln('Target newer than source, skipping build.');
} else {
verboseLog('Running mvn package for jni java sources to $buildPath.');
verboseLog('Running gradle task for building jni sources to $buildPath.');
await runCommand(
'mvn',
['package', '-Dtarget=${buildDir.absolute.path}'],
await findSources('jni', 'java'),
);
gradleWExecutable.toFilePath(windows: isWin),
[
'jar',
'-Pjni.targetDir=${buildDir.absolute.uri.toFilePath(windows: isWin)}',
],
await findSources('jni', 'java'));
}

for (var srcPath in sources) {
Expand All @@ -221,8 +253,10 @@ void main(List<String> arguments) async {
final targetFileUri = buildDir.uri.resolve(getTargetName(srcDir));
final targetFile = File.fromUri(targetFileUri);
if (!needsBuild(targetFile, srcDir)) {
verboseLog('Last modified of ${targetFile.path}: '
'${targetFile.lastModifiedSync()}.');
verboseLog(
'Last modified of ${targetFile.path}: '
'${targetFile.lastModifiedSync()}.',
);
stderr.writeln('Target newer than source, skipping build.');
continue;
}
Expand Down
39 changes: 39 additions & 0 deletions pkgs/jni/java/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
plugins {
java
application
}

repositories {
mavenCentral()
google()
}

dependencies {
implementation(libs.org.jetbrains.kotlin.kotlin.stdlib)
implementation(libs.org.jetbrains.kotlinx.kotlinx.coroutines.core)
}

group = "com.github.dart_lang"
description = "jni"

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

tasks.withType<Jar> {
val targetDir: String? = project.findProperty("jni.targetDir") as String?
if (targetDir != null) {
destinationDirectory = file(targetDir)
} else {
destinationDirectory = file("build/jni_libs")
}
}

tasks.withType<JavaCompile>() {
options.encoding = "UTF-8"
}

tasks.withType<Javadoc>() {
options.encoding = "UTF-8"
}
10 changes: 10 additions & 0 deletions pkgs/jni/java/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file was generated by the Gradle 'init' task.
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format

[versions]
org-jetbrains-kotlin-kotlin-stdlib = "1.6.20"
org-jetbrains-kotlinx-kotlinx-coroutines-core = "1.6.4"

[libraries]
org-jetbrains-kotlin-kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "org-jetbrains-kotlin-kotlin-stdlib" }
org-jetbrains-kotlinx-kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "org-jetbrains-kotlinx-kotlinx-coroutines-core" }
Binary file added pkgs/jni/java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions pkgs/jni/java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading