Skip to content

Optimize junit dependencies for each test target #303

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

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

brian-mcnamara
Copy link
Contributor

@brian-mcnamara brian-mcnamara commented Oct 22, 2024

This change simplifies the dependency list for the junit suite test targets by creating a export-only library used to group the dependencies together via an export-only java_library. The primary reason for this is to simplify the project model for IntelliJ using the new Bazel plugin. With this change, the IntelliJ model does not duplicate the dependencies for each test class in the Aspects and the internal project model and instead only refers to the java library.

Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

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

This makes sense. Thank you for the PR!

@shs96c shs96c merged commit 0739fc5 into bazel-contrib:main Nov 4, 2024
8 checks passed
@brian-mcnamara brian-mcnamara deleted the classpathOptimization branch November 4, 2024 17:30
@brian-mcnamara
Copy link
Contributor Author

Thanks @shs96c for taking a look! Is there plans to publish a release in the near future?

@brian-mcnamara
Copy link
Contributor Author

@shs96c would a release be possible, or is there one planned in the near future?

@shs96c
Copy link
Collaborator

shs96c commented Nov 16, 2024

We can push a release, but I'd like us to fix the artifact hashing algorithms first. My day job has been pretty busy, so I've not had much time to focus on that.

@brian-mcnamara
Copy link
Contributor Author

Totally understandable. Ill update us to use a commit in the mean time. Thanks for the update!

@@ -91,6 +91,26 @@ def create_jvm_test_suite(

tests = []

# Optimization for classpath, reduces the duplicate dependencies for each test to instead rely on one target
deps_lib_name = "%s-test-deps-lib" % name
define_library(
Copy link
Contributor

Choose a reason for hiding this comment

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

Not entirely sure but will these two new jars include test resources? We are seeing an issue when using liquibase in a test, as it complains about duplicated resources files from different jars.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will not create any jar as there are no sources to this library. It should only be a bazel construct which allows aspects to simplify the class path resolution.

Copy link
Contributor

@honnix honnix Apr 14, 2025

Choose a reason for hiding this comment

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

Hmm, that's not what we observe. Yes it doesn't contain any Java source code, but it contains test resources. Could it be https://github.com/brian-mcnamara/rules_jvm/blob/d899e276ff1a4a9b98272ed6cd31991f09d7839a/java/private/create_jvm_test_suite.bzl#L16? data might also be troublesome.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes that seems like the case. I think the only thing that we may need from that list is data (if supplied)

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry you are right that we do not have nontest_srcs for those cases, and it was indeed the case that resources would be duplicated in both -test-lib and the test jars, before your change.

Copy link
Contributor

Choose a reason for hiding this comment

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

That said, I think it is still not ideal having things duplicated. Maybe resources should not be included in -test-lib jar (I don't know the reason why they are explicitly included).

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooph, not great, but thanks for confirming my test was not doing something crazy. I agree it does not make sense to have resources included multiple times. Let me at least propose a PR and see where it goes :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#338 created PR, will see what the maintainers think of the approach.

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