1

As an example, say I have a program named Abc containing one class named Xyz. The code is located in a Git repository containing a single Eclipse project. I've adopted the Maven source directory layout. Before Java 9 the project structure might have looked like this (simplified):

Abc.git
|
+---.git
|
+---Abc
    |
    +---.settings
    |
    +---.project
    |
    +---.classpath
    |
    +---src
        |
        +---main
        |   |
        |   +---java (source folder)
        |       |
        |       +---com
        |           |
        |           +---abc
        |               |
        |               +---Xyz.java
        +---test
            |
            +---java (source folder)
                |
                +---com
                    |
                    +---abc
                        |
                        +---XyzTest.java

The JUnit tests were typically in the same packages as the production code, but in a different source folder. But now the production code is in a module. A package being tested can't be split into separate modules. Furthermore, some classes under test may reside in packages not exported by their module.

What is the correct practice in terms of code organization to address these issues?

This question is not about Maven. What I meant was: Is this the recommended way to do it?

Abc.git
|
+---.git
|
+---Abc
    |
    +---.settings
    |
    +---.project
    |
    +---.classpath
    |
    +---src
        |
        +---main
        |   |
        |   +---java
        |       |
        |       +---com.abc (source folder?)
        |           |
        |           +---module-info.java (exports com.abc)
        |           |
        |           +---com
        |               |
        |               +---abc
        |                   |
        |                   +---Xyz.java
        +---test
            |
            +---java
                |
                What goes here?
Zoe
  • 27,060
  • 21
  • 118
  • 148
Seiten
  • 138
  • 1
  • 13
  • Possible duplicate of [Where should I put unit tests when migrating a Java 8 project to Jigsaw](https://stackoverflow.com/questions/41366582/where-should-i-put-unit-tests-when-migrating-a-java-8-project-to-jigsaw) or Possible duplicate of [Using JUnit 5 with Java 9 without Maven or Gradle](https://stackoverflow.com/questions/46696451/using-junit-5-with-java-9-without-maven-or-gradle) – Naman Jan 09 '18 at 17:28
  • Not duplicates. – Seiten Jan 09 '18 at 17:37
  • 1
    Okay, please explain why not? – Naman Jan 09 '18 at 17:38
  • Currently, Eclipse supports one module per project, not per source folder. Be also aware of [this bug which has already been fixed and which will be released with the upcoming Oxygen.3 (4.7.3) on March 21, 2018](https://bugs.eclipse.org/bugs/show_bug.cgi?id=525948). May I ask what are the advantages of using modules in your own code? – howlger Jan 09 '18 at 20:30
  • 1
    Thank you, that's quite useful info. I don't really know what advantages would be. Basically I just thought modules were considered preferrable to not modules the same way generics is preferred to unchecked pre-Java 5 code. To me it's important to do things by the book because I'm perfectionist. – Seiten Jan 09 '18 at 22:56

0 Answers0