Scala library available in both compile and test configuration2019 Community Moderator ElectionIs the Scala 2.8 collections library a case of “the longest suicide note in history”?How do I run a scala ScalaTest in IntelliJ idea?sbteclipse: Managed dependencies not found by eclipsesbt: Add dependency on scalatest library. Where?Simple scalatest project won't be compiledAdd swf file in sbt processShould I include scala-compiler as a dependency in build.sbt?scalatest : object scalatest is not a member of package orgscala: delimited continuation issuesSBT doesn't compile tests located in custom test source folders

How are passwords stolen from companies if they only store hashes?

Why do tuner card drivers fail to build after kernel update to 4.4.0-143-generic?

How do I hide Chekhov's Gun?

"of which" is correct here?

What exactly is this small puffer fish doing and how did it manage to accomplish such a feat?

How do you talk to someone whose loved one is dying?

Math equation in non italic font

Is "upgrade" the right word to use in this context?

PTIJ: Who should I vote for? (21st Knesset Edition)

How should I state my peer review experience in the CV?

If I am holding an item before I cast Blink, will it move with me through the Ethereal Plane?

Welcoming 2019 Pi day: How to draw the letter π?

What are substitutions for coconut in curry?

Can I use USB data pins as power source

How could an airship be repaired midflight?

Why does energy conservation give me the wrong answer in this inelastic collision problem?

Why does overlay work only on the first tcolorbox?

Is a party consisting of only a bard, a cleric, and a warlock functional long-term?

combinatorics floor summation

How to pronounce "I ♥ Huckabees"?

A single argument pattern definition applies to multiple-argument patterns?

Employee lack of ownership

Instead of a Universal Basic Income program, why not implement a "Universal Basic Needs" program?

A diagram about partial derivatives of f(x,y)



Scala library available in both compile and test configuration



2019 Community Moderator ElectionIs the Scala 2.8 collections library a case of “the longest suicide note in history”?How do I run a scala ScalaTest in IntelliJ idea?sbteclipse: Managed dependencies not found by eclipsesbt: Add dependency on scalatest library. Where?Simple scalatest project won't be compiledAdd swf file in sbt processShould I include scala-compiler as a dependency in build.sbt?scalatest : object scalatest is not a member of package orgscala: delimited continuation issuesSBT doesn't compile tests located in custom test source folders










2















I have a library that I wish to expose in both the unit tests in Scala and the code itself.



In sbt, I added my library dependency with configuration "test" and then it's available for tests but I cannot use it in the code. If I leave the configuration be or add "compile" it's not available to be imported in unit tests.



libraryDependencies ++= Seq(
"org.scalacheck" %% "scalacheck" % "1.14.0",
"org.scalatest" %% "scalatest" % "3.0.6" % "test",
"org.scalactic" %% "scalactic" % "3.0.6" % "test")


The main problem is that I expose an abstract class I want to use all over the place in other code: abstract class UnitSpec extends FlatSpec with Matchers with ScalaCHeckDrivenPropertyChecks and also use in the tests of the library. If I add "test" to ScalaCheck it cannot find it in the main code of the library. If I leave it as is, it cannot from org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks. This used to be OK and work fine with 3.0.5 and GeneratorDrivenProperyChecks but that's been deprecated.



Is there a way to achieve what I want? I tried "test->compile" but that also doesn't do what I had hoped...










share|improve this question




























    2















    I have a library that I wish to expose in both the unit tests in Scala and the code itself.



    In sbt, I added my library dependency with configuration "test" and then it's available for tests but I cannot use it in the code. If I leave the configuration be or add "compile" it's not available to be imported in unit tests.



    libraryDependencies ++= Seq(
    "org.scalacheck" %% "scalacheck" % "1.14.0",
    "org.scalatest" %% "scalatest" % "3.0.6" % "test",
    "org.scalactic" %% "scalactic" % "3.0.6" % "test")


    The main problem is that I expose an abstract class I want to use all over the place in other code: abstract class UnitSpec extends FlatSpec with Matchers with ScalaCHeckDrivenPropertyChecks and also use in the tests of the library. If I add "test" to ScalaCheck it cannot find it in the main code of the library. If I leave it as is, it cannot from org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks. This used to be OK and work fine with 3.0.5 and GeneratorDrivenProperyChecks but that's been deprecated.



    Is there a way to achieve what I want? I tried "test->compile" but that also doesn't do what I had hoped...










    share|improve this question


























      2












      2








      2


      1






      I have a library that I wish to expose in both the unit tests in Scala and the code itself.



      In sbt, I added my library dependency with configuration "test" and then it's available for tests but I cannot use it in the code. If I leave the configuration be or add "compile" it's not available to be imported in unit tests.



      libraryDependencies ++= Seq(
      "org.scalacheck" %% "scalacheck" % "1.14.0",
      "org.scalatest" %% "scalatest" % "3.0.6" % "test",
      "org.scalactic" %% "scalactic" % "3.0.6" % "test")


      The main problem is that I expose an abstract class I want to use all over the place in other code: abstract class UnitSpec extends FlatSpec with Matchers with ScalaCHeckDrivenPropertyChecks and also use in the tests of the library. If I add "test" to ScalaCheck it cannot find it in the main code of the library. If I leave it as is, it cannot from org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks. This used to be OK and work fine with 3.0.5 and GeneratorDrivenProperyChecks but that's been deprecated.



      Is there a way to achieve what I want? I tried "test->compile" but that also doesn't do what I had hoped...










      share|improve this question
















      I have a library that I wish to expose in both the unit tests in Scala and the code itself.



      In sbt, I added my library dependency with configuration "test" and then it's available for tests but I cannot use it in the code. If I leave the configuration be or add "compile" it's not available to be imported in unit tests.



      libraryDependencies ++= Seq(
      "org.scalacheck" %% "scalacheck" % "1.14.0",
      "org.scalatest" %% "scalatest" % "3.0.6" % "test",
      "org.scalactic" %% "scalactic" % "3.0.6" % "test")


      The main problem is that I expose an abstract class I want to use all over the place in other code: abstract class UnitSpec extends FlatSpec with Matchers with ScalaCHeckDrivenPropertyChecks and also use in the tests of the library. If I add "test" to ScalaCheck it cannot find it in the main code of the library. If I leave it as is, it cannot from org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks. This used to be OK and work fine with 3.0.5 and GeneratorDrivenProperyChecks but that's been deprecated.



      Is there a way to achieve what I want? I tried "test->compile" but that also doesn't do what I had hoped...







      scala sbt






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 15:41







      Max Power

















      asked Mar 7 at 15:27









      Max PowerMax Power

      18911




      18911






















          2 Answers
          2






          active

          oldest

          votes


















          2














          You can combine configurations. In order to have a library both in compile and test you just add bot configurations.



          // wrong: libraryDependencies += "<organization>" %% "<module>" % "<version>" % "compile->compile" % "test->compile"


          The syntax means roughly: project configuration dependsOn(->) configuration of libraryDependency.



          Update



          You can also add the dependency twice with different configurations.



          libraryDependencies += "<organization>" %% "<module>" % "<version>",
          libraryDependencies += "<organization>" %% "<module>" % "<version>" % "test"


          Update 2



          I think the syntax in the first example is not what I meant to provide.



          libraryDependencies += "<organization>" %% "<module>" % "<version>" % "compile->compile;test->compile"


          At least that is what I use in my libraryDependencies.






          share|improve this answer

























          • When I do that I get Configurations already specified for module org.scalacheck:scalacheck:1.14.0:compile->compile. I also tried % "compile" % "test" but that gives me the same.

            – Max Power
            Mar 8 at 8:31











          • What does remote/local configuration mean in this context? I managed to get it working with a simple "compile;test" for the libraries that need to be in both. It did not work with the arrows.

            – Max Power
            Mar 13 at 8:03






          • 1





            I updated the answer with (hopefully) clearer wording. Imo the expanded syntax compile->compile is more expressive. However, you are right, one only really needs it if something more exotic is needed (e.g. if there are non standard configurations involved or someone would want to have compile depend on test code of a dependency 'compile->test' (weird, but happens).

            – Sascha Kolberg
            Mar 13 at 9:35


















          0














          So you need a trait from the Scalatest JAR in non-test code. I am not sure why it worked before, but it would make sense to me just to remove % "test" from the scalatest dependency. That will make it available in compile and everything from compile is available in test too.



          And for Scalactic I think the main use-case for it as a separate dependency is when you need it in compile but only use Scalatest in test (or don't use it at all). If they are both needed for tests only (or for compile), Scalatest will bring Scalactic with it.




          I tried "test->compile" but that also doesn't do what I had hoped...




          "test->compile" is the same as "test":





          A configuration without a mapping (no "->") is mapped to "default" or "compile". The -> is only needed when mapping to a different configuration than those.








          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%2f55047355%2fscala-library-available-in-both-compile-and-test-configuration%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            You can combine configurations. In order to have a library both in compile and test you just add bot configurations.



            // wrong: libraryDependencies += "<organization>" %% "<module>" % "<version>" % "compile->compile" % "test->compile"


            The syntax means roughly: project configuration dependsOn(->) configuration of libraryDependency.



            Update



            You can also add the dependency twice with different configurations.



            libraryDependencies += "<organization>" %% "<module>" % "<version>",
            libraryDependencies += "<organization>" %% "<module>" % "<version>" % "test"


            Update 2



            I think the syntax in the first example is not what I meant to provide.



            libraryDependencies += "<organization>" %% "<module>" % "<version>" % "compile->compile;test->compile"


            At least that is what I use in my libraryDependencies.






            share|improve this answer

























            • When I do that I get Configurations already specified for module org.scalacheck:scalacheck:1.14.0:compile->compile. I also tried % "compile" % "test" but that gives me the same.

              – Max Power
              Mar 8 at 8:31











            • What does remote/local configuration mean in this context? I managed to get it working with a simple "compile;test" for the libraries that need to be in both. It did not work with the arrows.

              – Max Power
              Mar 13 at 8:03






            • 1





              I updated the answer with (hopefully) clearer wording. Imo the expanded syntax compile->compile is more expressive. However, you are right, one only really needs it if something more exotic is needed (e.g. if there are non standard configurations involved or someone would want to have compile depend on test code of a dependency 'compile->test' (weird, but happens).

              – Sascha Kolberg
              Mar 13 at 9:35















            2














            You can combine configurations. In order to have a library both in compile and test you just add bot configurations.



            // wrong: libraryDependencies += "<organization>" %% "<module>" % "<version>" % "compile->compile" % "test->compile"


            The syntax means roughly: project configuration dependsOn(->) configuration of libraryDependency.



            Update



            You can also add the dependency twice with different configurations.



            libraryDependencies += "<organization>" %% "<module>" % "<version>",
            libraryDependencies += "<organization>" %% "<module>" % "<version>" % "test"


            Update 2



            I think the syntax in the first example is not what I meant to provide.



            libraryDependencies += "<organization>" %% "<module>" % "<version>" % "compile->compile;test->compile"


            At least that is what I use in my libraryDependencies.






            share|improve this answer

























            • When I do that I get Configurations already specified for module org.scalacheck:scalacheck:1.14.0:compile->compile. I also tried % "compile" % "test" but that gives me the same.

              – Max Power
              Mar 8 at 8:31











            • What does remote/local configuration mean in this context? I managed to get it working with a simple "compile;test" for the libraries that need to be in both. It did not work with the arrows.

              – Max Power
              Mar 13 at 8:03






            • 1





              I updated the answer with (hopefully) clearer wording. Imo the expanded syntax compile->compile is more expressive. However, you are right, one only really needs it if something more exotic is needed (e.g. if there are non standard configurations involved or someone would want to have compile depend on test code of a dependency 'compile->test' (weird, but happens).

              – Sascha Kolberg
              Mar 13 at 9:35













            2












            2








            2







            You can combine configurations. In order to have a library both in compile and test you just add bot configurations.



            // wrong: libraryDependencies += "<organization>" %% "<module>" % "<version>" % "compile->compile" % "test->compile"


            The syntax means roughly: project configuration dependsOn(->) configuration of libraryDependency.



            Update



            You can also add the dependency twice with different configurations.



            libraryDependencies += "<organization>" %% "<module>" % "<version>",
            libraryDependencies += "<organization>" %% "<module>" % "<version>" % "test"


            Update 2



            I think the syntax in the first example is not what I meant to provide.



            libraryDependencies += "<organization>" %% "<module>" % "<version>" % "compile->compile;test->compile"


            At least that is what I use in my libraryDependencies.






            share|improve this answer















            You can combine configurations. In order to have a library both in compile and test you just add bot configurations.



            // wrong: libraryDependencies += "<organization>" %% "<module>" % "<version>" % "compile->compile" % "test->compile"


            The syntax means roughly: project configuration dependsOn(->) configuration of libraryDependency.



            Update



            You can also add the dependency twice with different configurations.



            libraryDependencies += "<organization>" %% "<module>" % "<version>",
            libraryDependencies += "<organization>" %% "<module>" % "<version>" % "test"


            Update 2



            I think the syntax in the first example is not what I meant to provide.



            libraryDependencies += "<organization>" %% "<module>" % "<version>" % "compile->compile;test->compile"


            At least that is what I use in my libraryDependencies.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 13 at 9:32

























            answered Mar 7 at 18:24









            Sascha KolbergSascha Kolberg

            5,89112534




            5,89112534












            • When I do that I get Configurations already specified for module org.scalacheck:scalacheck:1.14.0:compile->compile. I also tried % "compile" % "test" but that gives me the same.

              – Max Power
              Mar 8 at 8:31











            • What does remote/local configuration mean in this context? I managed to get it working with a simple "compile;test" for the libraries that need to be in both. It did not work with the arrows.

              – Max Power
              Mar 13 at 8:03






            • 1





              I updated the answer with (hopefully) clearer wording. Imo the expanded syntax compile->compile is more expressive. However, you are right, one only really needs it if something more exotic is needed (e.g. if there are non standard configurations involved or someone would want to have compile depend on test code of a dependency 'compile->test' (weird, but happens).

              – Sascha Kolberg
              Mar 13 at 9:35

















            • When I do that I get Configurations already specified for module org.scalacheck:scalacheck:1.14.0:compile->compile. I also tried % "compile" % "test" but that gives me the same.

              – Max Power
              Mar 8 at 8:31











            • What does remote/local configuration mean in this context? I managed to get it working with a simple "compile;test" for the libraries that need to be in both. It did not work with the arrows.

              – Max Power
              Mar 13 at 8:03






            • 1





              I updated the answer with (hopefully) clearer wording. Imo the expanded syntax compile->compile is more expressive. However, you are right, one only really needs it if something more exotic is needed (e.g. if there are non standard configurations involved or someone would want to have compile depend on test code of a dependency 'compile->test' (weird, but happens).

              – Sascha Kolberg
              Mar 13 at 9:35
















            When I do that I get Configurations already specified for module org.scalacheck:scalacheck:1.14.0:compile->compile. I also tried % "compile" % "test" but that gives me the same.

            – Max Power
            Mar 8 at 8:31





            When I do that I get Configurations already specified for module org.scalacheck:scalacheck:1.14.0:compile->compile. I also tried % "compile" % "test" but that gives me the same.

            – Max Power
            Mar 8 at 8:31













            What does remote/local configuration mean in this context? I managed to get it working with a simple "compile;test" for the libraries that need to be in both. It did not work with the arrows.

            – Max Power
            Mar 13 at 8:03





            What does remote/local configuration mean in this context? I managed to get it working with a simple "compile;test" for the libraries that need to be in both. It did not work with the arrows.

            – Max Power
            Mar 13 at 8:03




            1




            1





            I updated the answer with (hopefully) clearer wording. Imo the expanded syntax compile->compile is more expressive. However, you are right, one only really needs it if something more exotic is needed (e.g. if there are non standard configurations involved or someone would want to have compile depend on test code of a dependency 'compile->test' (weird, but happens).

            – Sascha Kolberg
            Mar 13 at 9:35





            I updated the answer with (hopefully) clearer wording. Imo the expanded syntax compile->compile is more expressive. However, you are right, one only really needs it if something more exotic is needed (e.g. if there are non standard configurations involved or someone would want to have compile depend on test code of a dependency 'compile->test' (weird, but happens).

            – Sascha Kolberg
            Mar 13 at 9:35













            0














            So you need a trait from the Scalatest JAR in non-test code. I am not sure why it worked before, but it would make sense to me just to remove % "test" from the scalatest dependency. That will make it available in compile and everything from compile is available in test too.



            And for Scalactic I think the main use-case for it as a separate dependency is when you need it in compile but only use Scalatest in test (or don't use it at all). If they are both needed for tests only (or for compile), Scalatest will bring Scalactic with it.




            I tried "test->compile" but that also doesn't do what I had hoped...




            "test->compile" is the same as "test":





            A configuration without a mapping (no "->") is mapped to "default" or "compile". The -> is only needed when mapping to a different configuration than those.








            share|improve this answer





























              0














              So you need a trait from the Scalatest JAR in non-test code. I am not sure why it worked before, but it would make sense to me just to remove % "test" from the scalatest dependency. That will make it available in compile and everything from compile is available in test too.



              And for Scalactic I think the main use-case for it as a separate dependency is when you need it in compile but only use Scalatest in test (or don't use it at all). If they are both needed for tests only (or for compile), Scalatest will bring Scalactic with it.




              I tried "test->compile" but that also doesn't do what I had hoped...




              "test->compile" is the same as "test":





              A configuration without a mapping (no "->") is mapped to "default" or "compile". The -> is only needed when mapping to a different configuration than those.








              share|improve this answer



























                0












                0








                0







                So you need a trait from the Scalatest JAR in non-test code. I am not sure why it worked before, but it would make sense to me just to remove % "test" from the scalatest dependency. That will make it available in compile and everything from compile is available in test too.



                And for Scalactic I think the main use-case for it as a separate dependency is when you need it in compile but only use Scalatest in test (or don't use it at all). If they are both needed for tests only (or for compile), Scalatest will bring Scalactic with it.




                I tried "test->compile" but that also doesn't do what I had hoped...




                "test->compile" is the same as "test":





                A configuration without a mapping (no "->") is mapped to "default" or "compile". The -> is only needed when mapping to a different configuration than those.








                share|improve this answer















                So you need a trait from the Scalatest JAR in non-test code. I am not sure why it worked before, but it would make sense to me just to remove % "test" from the scalatest dependency. That will make it available in compile and everything from compile is available in test too.



                And for Scalactic I think the main use-case for it as a separate dependency is when you need it in compile but only use Scalatest in test (or don't use it at all). If they are both needed for tests only (or for compile), Scalatest will bring Scalactic with it.




                I tried "test->compile" but that also doesn't do what I had hoped...




                "test->compile" is the same as "test":





                A configuration without a mapping (no "->") is mapped to "default" or "compile". The -> is only needed when mapping to a different configuration than those.









                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 13 at 11:52

























                answered Mar 13 at 11:39









                Alexey RomanovAlexey Romanov

                109k26215356




                109k26215356



























                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047355%2fscala-library-available-in-both-compile-and-test-configuration%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

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme