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

Gradle modernization #1642

Open
wants to merge 4 commits into
base: gradle
Choose a base branch
from
Open

Gradle modernization #1642

wants to merge 4 commits into from

Conversation

rozza
Copy link
Member

@rozza rozza commented Mar 5, 2025

This PR comprises of 3 separate commits for the purpose of aiding reviewability.

The commits themselves aren't designed to be standalone (they are not) but rather compose separate areas of work that updating the build has required.

@rozza rozza force-pushed the JAVA-5758 branch 6 times, most recently from 0144d6e to aeda926 Compare March 6, 2025 13:35
@rozza rozza changed the base branch from gradle to main March 6, 2025 13:39
@rozza rozza changed the base branch from main to gradle March 6, 2025 13:40
@rozza rozza marked this pull request as draft March 6, 2025 13:42
@rozza rozza marked this pull request as ready for review March 6, 2025 14:49
@rozza rozza requested a review from katcharov March 6, 2025 14:49
@rozza rozza force-pushed the JAVA-5758 branch 4 times, most recently from 1ca551a to d80ee10 Compare March 11, 2025 14:25
@rozza rozza changed the title Gradle modernization to precompile build scripts Gradle modernization Mar 11, 2025
@rozza rozza removed the request for review from katcharov March 11, 2025 16:30
@rozza rozza marked this pull request as draft March 11, 2025 16:30
@rozza rozza force-pushed the JAVA-5758 branch 3 times, most recently from 5fa97ac to 3f03dbd Compare March 12, 2025 12:11
rozza added 3 commits March 12, 2025 17:51
Added library conventions and language based configurations.

- Added `doclets` to `buildSrc` for the `javadocs`
- Added `conventions` to centralize configuration of gradle plugins
- Added `projects` to handle project level conventions

JAVA-5758
JAVA-5757
Added library conventions and language based configurations.

- Updated to Gradle 8 (JAVA-5756)
- Removed `util:taglets` as now in `buildSrc`.
- Moved `util:spock` into `driver-core` as the annotation is now shared via `testArtifacts`.
- Added optional support (JAVA-5757)

JAVA-5756
JAVA-5758
JAVA-5757
Added library conventions and language based configurations.

- Refactored `JsonPoweredTestHelper` to handle either local and jar sources
- Refactored test cases to use new `JsonPoweredTestHelper.getTestDocuments` method
- Refactored test cases to normalize usage of loading test data
- Moved scala integration tests into a standardized `integerationTest` directory

JAVA-5758
@rozza
Copy link
Member Author

rozza commented Mar 12, 2025

Testing builds between main and JAVA-5758 branches.

Output testing

Manual checks

  • javadoc - ensured taglets output correctly
  • scaladoc - ensured mongo-scala-driver docs include the bson-scala scaladoc

The following shows how I tested / compared outputted pom.xml files, MANIFEST.MF files and the gradle tasks run when running the check command.

Generating build output for main:

git co main
./gradlew clean publishAllPublicationsToMaven2Repository

mkdir -p ./build/checks
branch_name=$(git rev-parse --abbrev-ref HEAD)
file_prefix="./build/checks/${branch_name}"

# output pom files &> /dev/null
find ./build/repo -name "*.pom" | xargs -I {} cat {} > ${file_prefix}-poms.txt

# output manifests &> /dev/null
find ./build/repo -regex ".*[[:digit:]]\.jar" | sort | xargs -I {} unzip -p {} META-INF/MANIFEST.MF  &> ${file_prefix}-manifests.txt

# check tasks list &> /dev/null
./gradlew check --dry-run | sort -o ${file_prefix}-check-tasks.txt

Generating build output for JAVA-5758:

Note: Here we also clean the previously created build/docs directory caused by publishing the main branch. Its needed to clean up elements-list artifacts that break javadoc.

git co JAVA-5758
rm -rf build/docs
./gradlew clean publishMavenToLocalBuildRepo 

mkdir -p ./build/checks
branch_name=$(git rev-parse --abbrev-ref HEAD)
file_prefix="./build/checks/${branch_name}"

# output pom files &> /dev/null
find ./build/repo -name "*.pom" | xargs -I {} cat {} > ${file_prefix}-poms.txt

# output manifests &> /dev/null
find ./build/repo -regex ".*[[:digit:]]\.jar" | sort | xargs -I {} unzip -p {} META-INF/MANIFEST.MF  &> ${file_prefix}-manifests.txt

# check tasks list &> /dev/null
./gradlew check --dry-run | sort -o ${file_prefix}-check-tasks.txt

Comparing output

Compare pom files ✅

Compare the main branch outputted poms with that of the new gradle build:

diff ./build/checks/main-poms.txt ./build/checks/JAVA-5758-poms.txt

Differences:

  • All BSON jars now have the url set to bson.org (not just the bson.jar)
  • All BSON jars use capitalized BSON (previously it was mixed BSON and Bson)
  • License url updated to use https (previously it was mixed)
  • developerConnection updated to use https: scm:https://github.com/mongodb/mongo-java-driver.git (git@github support has been removed)
  • Order of some dependencies may have changed (usually slf4j)
  • Scala libraries bumped to latest patch.

Compare manifests ✅

Compare the main branch outputted MAINFESTS with that of the new gradle build:

diff ./build/checks/main-manifests.txt ./build/checks/JAVA-5758-manifests.txt

Differences:

  • Build-Version updated - expected
  • Bnd-LastModified updated - expected
  • driver-legacy now has a manifest - side effect of the single publishing config

Compare check tasks ✅

Check any tasks that existed in main but not in JAVA-5758:

diff build/checks/main-check-tasks.txt build/checks/JAVA-5758-check-tasks.txt | grep ^\<  > build/checks/check-tasks-removals.txt
  • codenarc / compile groovy removed from projects without spock
  • checkstyle removed from non java projects
  • util project and all tasks removed

Check any tasks added to JAVA-5758:

diff build/checks/main-check-tasks.txt build/checks/JAVA-5758-check-tasks.txt | grep ^\>  > build/checks/check-tasks-additions.txt
  • Spotless tasks added to all projects
  • integrationTest tasks for kotlin
  • testJar added for test artifacts
  • buildSrc project added

Evergreen test counts

Env & task main JAVA-5758 Findings
latest Sharded Cluster Auth SSL JDK8 Linux test-core 4718 4776 ⬆️ Unknown: Possibly getData helper fetching more tests? - diff of logs wasn't instructive
latest Sharded Cluster Auth SSL JDK8 Linux test-legacy 1033 1033
latest Sharded Cluster Auth SSL JDK8 Linux test-reactive 3218 3218
latest Sharded Cluster Auth SSL JDK8 Linux test-sync 4454 4460 ⬆️
Load Balancer latest Auth SSL JDK21 Ubuntu 1826 1826
Scala 2.13 JDK17 7.0 Replica Set Ubuntu 944 944
Kotlin: JDK17 7.0 Replica Set Ubuntu 1314 1227 ⬇️ ⚠️ Now Fixed - Kotlin extensions had the wrong junit library
JDK8 Linux Unit test bson and crypt 3813 3813

Source Main: Evergreen main build
Source PR: Evergreen patch build

Issues found and fixed by this testing

  • Scala language dependencies updated to api from implementation to keep the poms the same.
  • slf4j dependencies updated to optionalAPI from optionalImplementation to keep poms the same.
  • bson-kotlinx dependencies for datetime and json serialization updated to optionalAPI from optionalImplementation to keep poms the same.
  • Fixed various mainfest attributes as they differed from previous versions
  • Fixed driver-kotlin-extensions testing and updated kotlin junit dependency in libs.versions.toml to use junit5.

@rozza rozza marked this pull request as ready for review March 13, 2025 14:37
@jyemin jyemin self-requested a review March 13, 2025 15:18
@rozza rozza requested review from a team and vbabanin and removed request for a team March 13, 2025 16:10
"BOM must not contain <scope> elements in dependency:\n$destination"
}
assert(it.getNode("optional") == null) {
"BOM must not contain <scope> elements in dependency:\n$destination"
Copy link
Contributor

@NathanQingyangXu NathanQingyangXu Mar 13, 2025

Choose a reason for hiding this comment

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

should be "BOM must not contain <optional> elements ..."?

@jyemin
Copy link
Collaborator

jyemin commented Mar 13, 2025

driver-legacy now has a manifest - side effect of the single publishing config

It was intentional that driver-legacy doesn't have a manifest (and also can never be a Java module). The reason is that OSGi requires that Java packages are segregated between modules, i.e. you can't have more than module containing types in the same Java package. And for various reasons, we were forced to do that with driver-legacy, as there are types in both core and legacy in the "com.mongodb" package (and same for "org.bson" in the bson module.

Is there a straightforward way to exclude the manifest for driver-legacy? I know there is at least one place where our module names are referenced in buildSrc. Maybe this is another one?

Copy link
Collaborator

@jyemin jyemin left a comment

Choose a reason for hiding this comment

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

I haven't reviewed the buildSrc directory yet.

}

/*
* Validate the Bom file.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Validate the Bom file.
* Validate the BOM file.

* Modify the generated POM to include all supported versions of Scala for driver-scala or bson-scala.
*/
configureMavenPublication {
components.findByName("javaPlatform")?.let { from(it) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this do?


@RunWith(classOf[JUnitRunner])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this no longer needed?

@@ -0,0 +1,38 @@
/*
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see a deleted build.gradle in this directory, but it's not in the source either. Where did it get deleted?

@@ -18,7 +18,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need the jetbrains one? I didn't know we depended on an artifact that contains this annotation?


configurations[integrationTest.implementationConfigurationName].extendsFrom(configurations.testImplementation.get())

configurations[integrationTest.runtimeOnlyConfigurationName].extendsFrom(configurations.testRuntimeOnly.get())
Copy link
Contributor

Choose a reason for hiding this comment

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

If you are tired of "integrationTestImplementation"(...), you might well replace the above two statements with

val integrationTestImplementation: Configuration by
configurations.getting { extendsFrom(configurations.implementation.get()) }
val integrationTestRuntimeOnly: Configuration by
configurations.getting { extendsFrom(configurations.runtimeOnly.get()) }

then you can use integrationTestImplementation(...) directly

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm. Further more configs are required. maybe not worth while.

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.

3 participants