Include test code in another module

Hello, I'm facing an issue with dependencies / class imports. For demonstration purposes, I have created a minimal reproduction repository: https://github.com/stechy1/java-module-test-issue There are two modules in the repository: submodule1 and submodule2. Submodule2 depends on submodule1. Dependent classes from submodule1 are visible in submodule2 without any issues. Same is for tests. So it means it is possible to create an instance of the class Example1 in the class Example2. Same is possible to do in Test2 with class Test1 from submodule1. Now the issue come, when java modules are activated. To do so, rename module-info.java.txt to module-info.java. The compilation fail, because class Test1 become not visible in class Test2. I have my own reasons why I'm trying to reach classes from submodule1 in submodule2. Also module-info is mandatory to be activated, because the whole project is using modules. Thank you for any ideas how to solve this issue. If you do not understand something, ping me, I will try explain better.
GitHub
GitHub - stechy1/java-module-test-issue: Minimal reproduction repos...
Minimal reproduction repository of an issue with including test files from one module to another. - GitHub - stechy1/java-module-test-issue: Minimal reproduction repository of an issue with includi...
14 Replies
JavaBot
JavaBot13mo ago
This post has been reserved for your question.
Hey @stechy1! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
stechy1
stechy1OP13mo ago
In my case it is a "compilation failure: can not find a symbol "Test1" in "Test2". Yes, it is required to use modules. I have quite a big project, which uses modules. Main reason: I wanted to learn, how things works...
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
stechy1
stechy1OP13mo ago
Yes, I was thinking about that, but than I will have an issue with module naming.
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
stechy1
stechy1OP13mo ago
but than I will loose access to package private classes and others in tests
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
stechy1
stechy1OP13mo ago
yeah, but it is kind of not desired in case of tests right?
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
stechy1
stechy1OP13mo ago
hm... 1. option is not possible, since I'm generating classes based on some resources and these generated classes should be available to other modules. 2. and 3. will break some stuff in my codebase 😄 For some reason I have to avoid creating module-info in my tests.
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
stechy1
stechy1OP13mo ago
Than maybe I missunderstand this option... Anyway, thank you for your ideas.
JavaBot
JavaBot13mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server