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

LUCENE-10328: Module path for compiling and running tests is wrong #571

Merged
merged 48 commits into from Jan 5, 2022

Conversation

dweiss
Copy link
Contributor

@dweiss dweiss commented Dec 27, 2021

No description provided.

… test fixtures plugin provides another layer of complexity to managing dependencies - the gain is so minimal here that I removed it.
…headFilter so that it's not picked up as a test.
… is a sad case of difference in how javac and ecj consider classes on module path vs. classpath
@dweiss dweiss marked this pull request as draft December 27, 2021 10:00
@uschindler
Copy link
Contributor

uschindler commented Jan 3, 2022

Hi @dweiss,
I merged main and reverted some changes in this PR that were solved differently than in other branch #567.

@uschindler
Copy link
Contributor

uschindler commented Jan 3, 2022

There is now a warning by ECJ, but does not fail build. I will fix this in main, sorry.

@uschindler uschindler closed this Jan 3, 2022
@uschindler uschindler reopened this Jan 3, 2022
@uschindler
Copy link
Contributor

Sorry, github was too slow and I accidentally pressed button twice.

@uschindler
Copy link
Contributor

Fixed warning

Copy link
Contributor

@uschindler uschindler left a comment

Choose a reason for hiding this comment

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

I do not fully understand all changes, but I hope that's fine. Everyday something new with modules.

At moment I have a few questions:

  • When are tests run as separate module (integration tests)? Is this decided based on the gradle name or the existence of a module-info.java inside the test's source dir?
  • When do we use module patching (I still see sometimes patching, but haven't figured out when it is done)? Do we run tests always inside the main sourcesets module (patching) or do we just run those in classpath (when the tests have no module-info.java?)

If you have some time, we can do a Zoom meeting to go through this patch. I am a bit lost.

I trust you so maybe commit it and I will se how it behaves.

lucene/core.tests/src/java/module-info.java Show resolved Hide resolved
gradle/java/modules.gradle Show resolved Hide resolved
@dweiss
Copy link
Contributor Author

dweiss commented Jan 5, 2022

Please take a look at this comment/ chart, Uwe.
https://issues.apache.org/jira/browse/LUCENE-10328?focusedCommentId=17468676&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17468676

How tests are run depends on the combination of whether source and test source sets are modules.

We do not have module patching. I don't think it's possible to configure gradle internal infrastructure and plugins to reasonably use it.

@uschindler
Copy link
Contributor

Please take a look at this comment/ chart, Uwe. https://issues.apache.org/jira/browse/LUCENE-10328?focusedCommentId=17468676&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17468676

How tests are run depends on the combination of whether source and test source sets are modules.

We do not have module patching. I don't think it's possible to configure gradle internal infrastructure and plugins to reasonably use it.

OK thanks for the picture. Much more information. I was hoping it is like that. That module patching does not work was known to me, I just stumbled on some support methods for it and I did not understand when they are used.

I am perfectly fine when we run our tests for a class in classpath mode, although the main sourceset is modular. Technically this won't change the test results, as UNIT tests should only check internal assertions. Of course in reality it is more complicated.

What I understood and which is missing in the image: The depenendecies are always modular, so lucene.core is put on module-path, even so we are running tests in classpath mode. This is waht this PR mainly changes, correct? reviously it was not fully working unless you explicitely declared it.

What we should now do (after this is merged):

  • Review implementation vs api dependencies (both on gradle and on module-info). With my other PR for test-random-chains i found an issue because of this. E.g. the phonetic module uses commons-codec also in its public API. Compilation of my module worked for some reason, but forbiddenapis failed, as it was not able to see the classes (when inspecting the method signatures). Which is understandable. Also ICU needs to refer to ICU in an API (gradle) / transitive (module-system) way. So we should enable the exports checks. When developing the last patch about logging in core, i would make java.logging still non-transitive, because it is unlikely that you would use it in downstream code (although theres a public signature using JUL). Because of that I added a SuppressWarnings("exports") on the class using it.
  • Fix up the module-decriptor files to figure out that all is sane

Uwe

gradle/java/modules.gradle Show resolved Hide resolved
@uschindler
Copy link
Contributor

I think you have to solve the conflicts caused by the change for running "gradlew beast". I leave that up to you. Maybe it works better after this branch is merged.

@@ -57,7 +57,7 @@ allprojects {
outputDir = project.javadoc.destinationDir
}

if (project.path == ':lucene:luke' || project.path.endsWith(".tests")) {
if (project.path == ':lucene:luke' || !(project in rootProject.ext.mavenProjects)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this mavenProjects?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah it is inverse. All projects that will land in Maven central. Yeah thats a better check.

Copy link
Contributor

Choose a reason for hiding this comment

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

by the way theres also the better operator project !in rootProject.ext.mavenProjects

I used is elsewhere already.

// Configure (tasks.test, sourceSets.test)
tasks.matching { it.name == "test" }.all { Test task ->
// Lazily configure (tasks.test, sourceSets.test)
tasks.matching { it.name ==~ /test(_[0-9]+)?/ }.all { Test task ->
Copy link
Contributor

Choose a reason for hiding this comment

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

I found that change, so you can merge by using "use mine".

Why can't we lazily find all test tasks using tasks.matching { it instance of Test }.all ?

Copy link
Contributor

Choose a reason for hiding this comment

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

We shoudl also check that instrumentation with Emma works.

Copy link
Contributor

Choose a reason for hiding this comment

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

I found that change, so you can merge by using "use mine".

Why can't we lazily find all test tasks using tasks.matching { it instance of Test }.all ?

Or use: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskCollection.html#withType-java.lang.Class-

@dweiss
Copy link
Contributor Author

dweiss commented Jan 5, 2022

The depenendecies are always modular, so lucene.core is put on module-path, even so we are running tests in classpath mode. This is waht this PR mainly changes, correct? reviously it was not fully working unless you explicitely declared it.

lucene.core (and any other dependency placed in modular configurations) is correctly inserted on module-path if this reference is from "outside" the project itself. In other words, the tests within lucene.core run with main source set classes on classpath (otherwise you'd have split package errors) but anywhere else where you reference lucene.core, it will be placed on module-path.

That debug flag (-Pbuild.debug.paths=true) shows verbosely how classpath and module path is configured for each task.

@dweiss dweiss merged commit ff547e7 into apache:main Jan 5, 2022
dweiss added a commit to dweiss/lucene that referenced this pull request Jan 5, 2022
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