JDK9 Automatic Modules and “Split Packages” Dependencies









up vote
0
down vote

favorite
1












I am converting a java project to use modules. One of my modules depends on hamcrest library, and it needs both of the jar files hamcrest.core and hamcrest.library. These two jar files both have org.hamcrest package. So when my module wants to treat these two jars as automatic modules, it fails because two modules in a module-path cannot have packages with same name. I searched a lot and found some related stuff on stackoverflow. It seems that I have two reasonable options if I do not want to rebuild those dependencies:



  1. Merge the two jars into one jar using my build automation tool (which is maven).

  2. Somehow tell java compiler that these two jars should be treated as a single automatic module.

So here are my questions:



  • Is any of these two options possible? If yes, how?

  • Is there any better option?

Thanks in advance










share|improve this question

















  • 3




    The cleanest of all solutions would be to report and get it fixed in the library itself. Some links/reports useful in such cases -github.com/hamcrest/JavaHamcrest/issues/187, github.com/hamcrest/JavaHamcrest/issues/205
    – nullpointer
    Nov 11 at 5:18










  • That's right for sure but I am in hurry :)
    – Feri
    Nov 11 at 16:52










  • Did you try to let those jars remain on the classpath instead of modulepath to result into an unnamed module? Not sure though that would be something you're looking for.
    – nullpointer
    Nov 11 at 17:07











  • Unfortunately explicit module cannot read classpath. It says if the explicit module is treatd as unnamed module "TEMPORARILY", that would work but I've no idea what this even means!
    – Feri
    Nov 11 at 18:34















up vote
0
down vote

favorite
1












I am converting a java project to use modules. One of my modules depends on hamcrest library, and it needs both of the jar files hamcrest.core and hamcrest.library. These two jar files both have org.hamcrest package. So when my module wants to treat these two jars as automatic modules, it fails because two modules in a module-path cannot have packages with same name. I searched a lot and found some related stuff on stackoverflow. It seems that I have two reasonable options if I do not want to rebuild those dependencies:



  1. Merge the two jars into one jar using my build automation tool (which is maven).

  2. Somehow tell java compiler that these two jars should be treated as a single automatic module.

So here are my questions:



  • Is any of these two options possible? If yes, how?

  • Is there any better option?

Thanks in advance










share|improve this question

















  • 3




    The cleanest of all solutions would be to report and get it fixed in the library itself. Some links/reports useful in such cases -github.com/hamcrest/JavaHamcrest/issues/187, github.com/hamcrest/JavaHamcrest/issues/205
    – nullpointer
    Nov 11 at 5:18










  • That's right for sure but I am in hurry :)
    – Feri
    Nov 11 at 16:52










  • Did you try to let those jars remain on the classpath instead of modulepath to result into an unnamed module? Not sure though that would be something you're looking for.
    – nullpointer
    Nov 11 at 17:07











  • Unfortunately explicit module cannot read classpath. It says if the explicit module is treatd as unnamed module "TEMPORARILY", that would work but I've no idea what this even means!
    – Feri
    Nov 11 at 18:34













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I am converting a java project to use modules. One of my modules depends on hamcrest library, and it needs both of the jar files hamcrest.core and hamcrest.library. These two jar files both have org.hamcrest package. So when my module wants to treat these two jars as automatic modules, it fails because two modules in a module-path cannot have packages with same name. I searched a lot and found some related stuff on stackoverflow. It seems that I have two reasonable options if I do not want to rebuild those dependencies:



  1. Merge the two jars into one jar using my build automation tool (which is maven).

  2. Somehow tell java compiler that these two jars should be treated as a single automatic module.

So here are my questions:



  • Is any of these two options possible? If yes, how?

  • Is there any better option?

Thanks in advance










share|improve this question













I am converting a java project to use modules. One of my modules depends on hamcrest library, and it needs both of the jar files hamcrest.core and hamcrest.library. These two jar files both have org.hamcrest package. So when my module wants to treat these two jars as automatic modules, it fails because two modules in a module-path cannot have packages with same name. I searched a lot and found some related stuff on stackoverflow. It seems that I have two reasonable options if I do not want to rebuild those dependencies:



  1. Merge the two jars into one jar using my build automation tool (which is maven).

  2. Somehow tell java compiler that these two jars should be treated as a single automatic module.

So here are my questions:



  • Is any of these two options possible? If yes, how?

  • Is there any better option?

Thanks in advance







java maven java-9 hamcrest java-module






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 3:37









Feri

110110




110110







  • 3




    The cleanest of all solutions would be to report and get it fixed in the library itself. Some links/reports useful in such cases -github.com/hamcrest/JavaHamcrest/issues/187, github.com/hamcrest/JavaHamcrest/issues/205
    – nullpointer
    Nov 11 at 5:18










  • That's right for sure but I am in hurry :)
    – Feri
    Nov 11 at 16:52










  • Did you try to let those jars remain on the classpath instead of modulepath to result into an unnamed module? Not sure though that would be something you're looking for.
    – nullpointer
    Nov 11 at 17:07











  • Unfortunately explicit module cannot read classpath. It says if the explicit module is treatd as unnamed module "TEMPORARILY", that would work but I've no idea what this even means!
    – Feri
    Nov 11 at 18:34













  • 3




    The cleanest of all solutions would be to report and get it fixed in the library itself. Some links/reports useful in such cases -github.com/hamcrest/JavaHamcrest/issues/187, github.com/hamcrest/JavaHamcrest/issues/205
    – nullpointer
    Nov 11 at 5:18










  • That's right for sure but I am in hurry :)
    – Feri
    Nov 11 at 16:52










  • Did you try to let those jars remain on the classpath instead of modulepath to result into an unnamed module? Not sure though that would be something you're looking for.
    – nullpointer
    Nov 11 at 17:07











  • Unfortunately explicit module cannot read classpath. It says if the explicit module is treatd as unnamed module "TEMPORARILY", that would work but I've no idea what this even means!
    – Feri
    Nov 11 at 18:34








3




3




The cleanest of all solutions would be to report and get it fixed in the library itself. Some links/reports useful in such cases -github.com/hamcrest/JavaHamcrest/issues/187, github.com/hamcrest/JavaHamcrest/issues/205
– nullpointer
Nov 11 at 5:18




The cleanest of all solutions would be to report and get it fixed in the library itself. Some links/reports useful in such cases -github.com/hamcrest/JavaHamcrest/issues/187, github.com/hamcrest/JavaHamcrest/issues/205
– nullpointer
Nov 11 at 5:18












That's right for sure but I am in hurry :)
– Feri
Nov 11 at 16:52




That's right for sure but I am in hurry :)
– Feri
Nov 11 at 16:52












Did you try to let those jars remain on the classpath instead of modulepath to result into an unnamed module? Not sure though that would be something you're looking for.
– nullpointer
Nov 11 at 17:07





Did you try to let those jars remain on the classpath instead of modulepath to result into an unnamed module? Not sure though that would be something you're looking for.
– nullpointer
Nov 11 at 17:07













Unfortunately explicit module cannot read classpath. It says if the explicit module is treatd as unnamed module "TEMPORARILY", that would work but I've no idea what this even means!
– Feri
Nov 11 at 18:34





Unfortunately explicit module cannot read classpath. It says if the explicit module is treatd as unnamed module "TEMPORARILY", that would work but I've no idea what this even means!
– Feri
Nov 11 at 18:34













1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Ok I finally managed to solve it like this:



  1. Create a new maven module called hamcrest-all and add dependencies on hamcrest-core and hamcrest-library.

  2. add maven-assembly-plugin to this module with appendAssemblyId set to false.

  3. remove the dependency to hamcrest-core and hamcrest-library from other maven modules and instead add dependency to hamcrest-all.

  4. exclude hamcrest-core and hamcrest-library when including dependency to hamcrest-all.

What it actually does is that it unpacks hamcrest-core and hamcrest-library in the jar file created for hamrest-all. And because each jar file is treated as one module by JMPS, the problem is gone :)






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245628%2fjdk9-automatic-modules-and-split-packages-dependencies%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    Ok I finally managed to solve it like this:



    1. Create a new maven module called hamcrest-all and add dependencies on hamcrest-core and hamcrest-library.

    2. add maven-assembly-plugin to this module with appendAssemblyId set to false.

    3. remove the dependency to hamcrest-core and hamcrest-library from other maven modules and instead add dependency to hamcrest-all.

    4. exclude hamcrest-core and hamcrest-library when including dependency to hamcrest-all.

    What it actually does is that it unpacks hamcrest-core and hamcrest-library in the jar file created for hamrest-all. And because each jar file is treated as one module by JMPS, the problem is gone :)






    share|improve this answer
























      up vote
      0
      down vote



      accepted










      Ok I finally managed to solve it like this:



      1. Create a new maven module called hamcrest-all and add dependencies on hamcrest-core and hamcrest-library.

      2. add maven-assembly-plugin to this module with appendAssemblyId set to false.

      3. remove the dependency to hamcrest-core and hamcrest-library from other maven modules and instead add dependency to hamcrest-all.

      4. exclude hamcrest-core and hamcrest-library when including dependency to hamcrest-all.

      What it actually does is that it unpacks hamcrest-core and hamcrest-library in the jar file created for hamrest-all. And because each jar file is treated as one module by JMPS, the problem is gone :)






      share|improve this answer






















        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        Ok I finally managed to solve it like this:



        1. Create a new maven module called hamcrest-all and add dependencies on hamcrest-core and hamcrest-library.

        2. add maven-assembly-plugin to this module with appendAssemblyId set to false.

        3. remove the dependency to hamcrest-core and hamcrest-library from other maven modules and instead add dependency to hamcrest-all.

        4. exclude hamcrest-core and hamcrest-library when including dependency to hamcrest-all.

        What it actually does is that it unpacks hamcrest-core and hamcrest-library in the jar file created for hamrest-all. And because each jar file is treated as one module by JMPS, the problem is gone :)






        share|improve this answer












        Ok I finally managed to solve it like this:



        1. Create a new maven module called hamcrest-all and add dependencies on hamcrest-core and hamcrest-library.

        2. add maven-assembly-plugin to this module with appendAssemblyId set to false.

        3. remove the dependency to hamcrest-core and hamcrest-library from other maven modules and instead add dependency to hamcrest-all.

        4. exclude hamcrest-core and hamcrest-library when including dependency to hamcrest-all.

        What it actually does is that it unpacks hamcrest-core and hamcrest-library in the jar file created for hamrest-all. And because each jar file is treated as one module by JMPS, the problem is gone :)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 at 23:27









        Feri

        110110




        110110



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245628%2fjdk9-automatic-modules-and-split-packages-dependencies%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo