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

Update PMD to 7.0.0 #689

Merged
merged 14 commits into from Apr 17, 2024
Merged

Update PMD to 7.0.0 #689

merged 14 commits into from Apr 17, 2024

Conversation

zod
Copy link
Collaborator

@zod zod commented Apr 3, 2024

PMD has finally released version 7.0.0 which offers better analysis and new rules.

It required a gradle update but Android Studio kept nagging me to upgrade gradle & AGP (Android Gradle Plugin) anyway...

build.gradle Outdated
@@ -7,7 +7,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'com.android.tools.build:gradle:8.3.1'
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that many developers use IDEA instead of Android Studio.

Latest IDEA does not still support the Android Gradle plugin 8.3.X.
IDEA works fine with Android Gradle plugin 8.2.X (currently 8.2.2).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess we don't use any features from 8.3.x, so switching back to 8.2.2 shoudn't cause any issues.

@@ -16,10 +16,10 @@ jobs:
environment: BRouter
steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
- name: Set up JDK 17
Copy link
Collaborator

Choose a reason for hiding this comment

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

One remark only, the BRouter server still uses JDK 11.
Therefore, the output lib cannot be used directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we want to compile for older Java releases we should target a specific java version. It seems reasonable to target Java 11 but use JDK 17 to build.

Copy link
Contributor

Choose a reason for hiding this comment

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

For maximum compatibility with old Android versions (that do not contain newer Java API),
in the open source libraries I maintain, we may use Java 17 to compile,
but have sourceCompatibility and targetCompatibility with JavaVersion.VERSION_1_8.

For example:
https://github.com/mapsforge/mapsforge/blob/master/build.gradle#L32-L33
https://github.com/mapsforge/vtm/blob/master/build.gradle#L34-L35

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fine, I could try sourceCompatibility and targetCompatibility next week with the test server.

@zod zod marked this pull request as draft April 5, 2024 22:34
@zod
Copy link
Collaborator Author

zod commented Apr 5, 2024

I've implemented targeting a specific Java version using conventions plugins because the gradle documentation suggested to avoid cross configuration using allprojects/subprojects

Currently it targets Java 11 because we already use some functionality from Java 9. It's mostly in test code but the new Hgt processing also uses it. This code won't be run on Android so it should not cause any issues. Going forward we should pick a Java version we really want to target and adopt the build configuration to treat using newer code as error.

I'd also like to add a dependency from distZip target to :brouter-routing-app:packageRelease to ensure it's built before distZip, but unfortunately adding this dependency won't work if the android SDK isn't present because the target isn't defined. If you have any suggestions I would be very happy :)

@afischerdev
Copy link
Collaborator

I made some tests:

  • export repository as zip and run Android Studio / gradle command line
  • export repo as git export and run Android Studio ( gradle command line
  • use the generated lib as test-server lib
    All tests passed ok.
    So I would like to merge after version 1.7.4

@afischerdev
Copy link
Collaborator

I'd also like to add a dependency from distZip ...

As you see in the current release, the distribution file is not produced.
I used

distZip {
    dependsOn fatJar
    dependsOn (':brouter-routing-app:assemble')
    archiveFileName = 'brouter-' + project.version + '.zip'
}

@zod
Copy link
Collaborator Author

zod commented Apr 9, 2024

Your suggestion would break builds without android SDK because the :brouter-routing-app:assemble wouldn't exist. The docker build doesn't add the android SDK and therefore would fail.

@afischerdev
Copy link
Collaborator

Yes, you are right. This is only a temporary solution to get an apk inside the zip when Android tasks are present.
My attempts with doLast or Exception were unsuccessful. So no idea at the moment.

@afischerdev
Copy link
Collaborator

I've masked the dependencies now, that should do the job.

if (file('../local.properties').exists()) dependsOn (':brouter-routing-app:assemble')

@zod zod marked this pull request as ready for review April 15, 2024 18:50
@zod
Copy link
Collaborator Author

zod commented Apr 15, 2024

I'm not to happy with this check because not we check for local.properties in multiple locations instead of detecting if the target was added, but let's just use it for now and perhaps I'll come up with a different check in a future PR.

@afischerdev
Copy link
Collaborator

@zod
I understand that, but we already use this way in settings.gradle.
My tests with hasProperty('sdk.dir') or similar were not successful. My be there are other ideas?

@afischerdev afischerdev merged commit 36e169a into abrensch:master Apr 17, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants