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

i123643 print java version gradle #123644

Merged
merged 42 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
143d5b7
Add task to projects evaluated by flutter.gradle that will print the …
reidbaker Mar 28, 2023
6a8fd7e
Add integration test to verify javaVersion output
reidbaker Mar 28, 2023
f87405b
Merge branch 'master' into i123643-print-java-version-gradle
reidbaker Mar 28, 2023
3a05741
Merge branch 'master' into i123643-print-java-version-gradle
reidbaker Mar 29, 2023
be1e267
Rename test to include _test prefix, update warning to say why the na…
reidbaker Mar 29, 2023
8c606f2
wrap println in a doLast and add warning about speed of gradle tasks
reidbaker Mar 30, 2023
f60f9e0
Fix android_gradle_version_test to run on windows, add gradlew utilit…
reidbaker Mar 30, 2023
368e1c3
Merge branch 'master' into i123643-print-java-version-gradle
reidbaker Mar 30, 2023
35e5dfd
Fix formatting
reidbaker Mar 30, 2023
bb8a586
Fix dart doc formatting for getGradleFileName
reidbaker Mar 30, 2023
982ffb0
Merge branch 'master' into i123643-print-java-version-gradle
reidbaker Apr 2, 2023
7745651
Merge branch 'master' into i123643-print-java-version-gradle
reidbaker Apr 4, 2023
ecf437b
Add adaptive constructor to Radio and RadioListTile (#123816)
MitchellGoodwin Apr 4, 2023
dac83d7
Rename Sample classes (#124080)
gspencergoog Apr 4, 2023
efea3e3
Better support for wireless devices in IDEs (#123716)
vashworth Apr 4, 2023
2b80071
[flutter_tools] Remove --no-sound-null-safety #4 (#124039)
christopherfujino Apr 4, 2023
70f41ce
Add flag to filter by device connection interface (#124034)
vashworth Apr 4, 2023
1c4204f
Allow --ipv6 flag for flutter attach on iOS devices (#123822)
vashworth Apr 4, 2023
53741b1
Always use the canvaskit path from the web sdk. (#123915)
eyebrowsoffire Apr 4, 2023
7539b73
FIX: SegmentedButton segments background cannot be made transparent (…
rydmike Apr 4, 2023
f053468
Move analyzer_benchmark_vm to vm (#124147)
keyonghan Apr 4, 2023
8930a50
Adds i18n to widget layer (#123620)
chunhtai Apr 4, 2023
dbd2022
Fix `clipBehavior` for `Drawer` with shape and add `clipBehavior` pro…
TahaTesser Apr 4, 2023
884498c
Reland "Serve DevTools when running flutter test (#123607)" (#124058)
bkonyi Apr 4, 2023
2c7bf0a
Roll Flutter Engine from 8edd3c000a39 to 3e5f27d4812e (3 revisions) (…
engine-flutter-autoroll Apr 4, 2023
ef3747d
Roll Flutter Engine from 3e5f27d4812e to 65515adfb5eb (5 revisions) (…
engine-flutter-autoroll Apr 5, 2023
d8c11ec
[platform_view]fix iOS platform view's focus node leakage (#124066)
hellohuanlin Apr 5, 2023
f0b91fb
Roll Flutter Engine from 65515adfb5eb to 4219c72ac8f0 (1 revision) (#…
engine-flutter-autoroll Apr 5, 2023
afc5877
[flutter_tools] Include mode in app.start event, and forward app.star…
DanTup Apr 5, 2023
ddd74be
Roll Flutter Engine from 4219c72ac8f0 to db23c3fbe0b0 (4 revisions) (…
engine-flutter-autoroll Apr 5, 2023
04001c5
[macOS] Remigrate principal class to NSApplication (#124173)
cbracken Apr 5, 2023
7b67f81
Revert "Fix scrolling in the `Drawer` and `NavigationDrawer` trigger…
Piinks Apr 5, 2023
986ecdb
Add CustomDimensions.commandRunIsTest (#124135)
goderbauer Apr 5, 2023
3cee9ff
Roll Flutter Engine from db23c3fbe0b0 to 67467127295d (1 revision) (#…
engine-flutter-autoroll Apr 5, 2023
e9561e8
Add analytics package + setTelemetry method attached (#124015)
eliasyishak Apr 5, 2023
312eb3f
Add Java-Gradle-AGP validation to flutter analyze (#123916)
reidbaker Apr 5, 2023
91a7d85
Merge remote-tracking branch 'origin/master' into i123643-print-java-…
reidbaker Apr 5, 2023
3ad20d6
Dont depend on another test file
reidbaker Apr 5, 2023
8ad6784
Dont depend on another test file
reidbaker Apr 6, 2023
720b948
Merge branch 'master' into i123643-print-java-version-gradle
reidbaker Apr 13, 2023
4261e86
Use platform path seperator to use .\ on windows
reidbaker Apr 13, 2023
c151ec1
Merge branch 'master' into i123643-print-java-version-gradle
reidbaker Apr 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/flutter_tools/gradle/flutter.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,23 @@ class FlutterPlugin implements Plugin<Project> {
project.dependencies.add(configuration, dependency, config)
}

// Add a task that can be called on flutter projects that prints the java version used in gradle.
//
// Format of the output of this task can be used in debugging what version of java gradle is using.
// Not recomended for use in time sensitive commands like `flutter run` or `flutter build` as
// gradle is slower than we want. Particularly in light of https://github.com/flutter/flutter/issues/119196.
//
private static void addTaskForJavaVersion(Project project) {
// Warning: the name of this task is used by other code. Change with caution.
project.tasks.register('javaVersion') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about calling it (print/show/get)JavaVersion? And is the warning for possible edits to the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally I had printJavaVersion which would be run as ./gradlew -q printJavaVersion but this is a task not a gradle function and thought ./gradlew -q javaVersion actually read more clean.

The warning is for possible changes to the name since I am not aware of anything. I can make the warning more clear. " Warning: the name of this task is used by other code. Change with caution."

description 'Print the current java version used by gradle. '
'see: https://docs.gradle.org/current/javadoc/org/gradle/api/JavaVersion.html'
doLast {
println(JavaVersion.current())
}
}
}

/**
* Returns a Flutter build mode suitable for the specified Android buildType.
*
Expand Down Expand Up @@ -850,6 +867,7 @@ class FlutterPlugin implements Plugin<Project> {
if (project.hasProperty('validate-deferred-components')) {
validateDeferredComponentsValue = project.property('validate-deferred-components').toBoolean()
}
addTaskForJavaVersion(project)
def targetPlatforms = getTargetPlatforms()
def addFlutterDeps = { variant ->
if (shouldSplitPerAbi()) {
Expand Down
14 changes: 11 additions & 3 deletions packages/flutter_tools/lib/src/android/gradle_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ class GradleUtils {
final Directory androidDir = project.android.hostAppGradleRoot;
injectGradleWrapperIfNeeded(androidDir);

final File gradle = androidDir.childFile(
_platform.isWindows ? 'gradlew.bat' : 'gradlew',
);
final File gradle = androidDir.childFile(getGradlewFileName(_platform));

if (gradle.existsSync()) {
_logger.printTrace('Using gradle from ${gradle.absolute.path}.');
// If the Gradle executable doesn't have execute permission,
Expand Down Expand Up @@ -290,3 +289,12 @@ void exitWithNoSdkMessage() {
'Try setting the ANDROID_SDK_ROOT environment variable.'
);
}

// return gradlew file name based on the platform.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// return gradlew file name based on the platform.
// Returns gradlew file name based on the platform.

String getGradlewFileName(Platform platform) {
if (platform.isWindows) {
return 'gradlew.bat';
} else {
return 'gradlew';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,11 @@ void main() {
androidDirectory.childFile('gradlew').path,
);
});
testWithoutContext('getGradleFileName for notWindows', () {
expect(getGradlewFileName(notWindowsPlatform), 'gradlew');
});
testWithoutContext('getGradleFileName for windows', () {
expect(getGradlewFileName(windowsPlatform), 'gradlew.bat');
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:file/file.dart';
import 'package:flutter_tools/src/android/gradle_utils.dart'
show getGradlewFileName;
import 'package:flutter_tools/src/base/io.dart';

import '../src/common.dart';
import 'test_utils.dart';

void main() {
late Directory tempDir;

setUp(() async {
tempDir = createResolvedTempDirectorySync('run_test.');
});

tearDown(() async {
tryToDelete(tempDir);
});

testWithoutContext(
'gradle task exists named javaVersion that prints jdk version', () async {
// Create a new flutter project.
final String flutterBin =
fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
ProcessResult result = await processManager.run(<String>[
flutterBin,
'create',
tempDir.path,
'--project-name=testapp',
], workingDirectory: tempDir.path);
expect(result.exitCode, 0);
// Ensure that gradle files exists from templates.
result = await processManager.run(<String>[
flutterBin,
'build',
'apk',
'--config-only',
], workingDirectory: tempDir.path);
expect(result.exitCode, 0);

final Directory androidApp = tempDir.childDirectory('android');
result = await processManager.run(<String>[
'./${getGradlewFileName(platform)}',
...getLocalEngineArguments(),
'-q', // quiet output.
'javaVersion',
], workingDirectory: androidApp.path);
// Verify that gradlew has a javaVersion task.
expect(result.exitCode, 0);
// Verify the format is a number on its own line.
expect(result.stdout.toString(), matches(RegExp(r'\d\n')));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 questions:

  1. should we be matching 1 or more digits?
  2. would this never be a \r\n on Windows?

Copy link
Contributor Author

@reidbaker reidbaker Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. yes updated.
  2. Maybe, I think I will update this to use the end of line sequence instead.

});
}