Exclude test folder from maven buildCreate ArrayList from arrayHow can I create an executable JAR with dependencies using Maven?How to add local jar files to a Maven project?IntelliJ inspection gives “Cannot resolve symbol” but still compiles codeExclude Test Classes in dependend Maven JARHow do you “Mavenize” a project using Intellij?Maven is not working in Java 8 when Javadoc tags are incompleteBuilding a maven jar for TestNG automation projectMaven - Wrong folder structureMaven spring-boot ueber-jar and lib

How can bays and straits be determined in a procedurally generated map?

Dragon forelimb placement

strToHex ( string to its hex representation as string)

Why can't I see bouncing of a switch on an oscilloscope?

Can a Warlock become Neutral Good?

What does "Puller Prush Person" mean?

"to be prejudice towards/against someone" vs "to be prejudiced against/towards someone"

Fencing style for blades that can attack from a distance

Fully-Firstable Anagram Sets

How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?

TGV timetables / schedules?

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?

Problem of parity - Can we draw a closed path made up of 20 line segments...

What's the output of a record cartridge playing an out-of-speed record

Show that if two triangles built on parallel lines, with equal bases have the same perimeter only if they are congruent.

Prove that NP is closed under karp reduction?

Font hinting is lost in Chrome-like browsers (for some languages )

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

What defenses are there against being summoned by the Gate spell?

Smoothness of finite-dimensional functional calculus

Why not use SQL instead of GraphQL?

Arthur Somervell: 1000 Exercises - Meaning of this notation

How is it possible to have an ability score that is less than 3?

How to say job offer in Mandarin/Cantonese?



Exclude test folder from maven build


Create ArrayList from arrayHow can I create an executable JAR with dependencies using Maven?How to add local jar files to a Maven project?IntelliJ inspection gives “Cannot resolve symbol” but still compiles codeExclude Test Classes in dependend Maven JARHow do you “Mavenize” a project using Intellij?Maven is not working in Java 8 when Javadoc tags are incompleteBuilding a maven jar for TestNG automation projectMaven - Wrong folder structureMaven spring-boot ueber-jar and lib






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















This is one of the most asked questions here in so... but why any answer works for me? i believe i have somehow a wrong maven structure in my project



I have a project like



basedir
|-src
|--many many many packages
|-test
|--testpackages
|-pom.xml


So my pom.xml is in the same level as src and test folders and it isn't the typical structure like java/main/ java/test... it is the root of the project folder



<build>
<sourceDirectory>$basedir/src</sourceDirectory>
<testSourceDirectory>$basedir/test</testSourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>

<configuration>
<source>1.7</source>
<target>1.7</target>
<excludes>
<exclude>**/test/**</exclude>
</excludes>
</configuration>


</plugin>

</plugins>
</build>


but when i run maven install and open the generated jar the folder test is in there...
how can i solve and make it ignore this folder?










share|improve this question

















  • 1





    <exclude>test/**</exclude>

    – Micho Rizo
    Mar 8 at 5:20

















0















This is one of the most asked questions here in so... but why any answer works for me? i believe i have somehow a wrong maven structure in my project



I have a project like



basedir
|-src
|--many many many packages
|-test
|--testpackages
|-pom.xml


So my pom.xml is in the same level as src and test folders and it isn't the typical structure like java/main/ java/test... it is the root of the project folder



<build>
<sourceDirectory>$basedir/src</sourceDirectory>
<testSourceDirectory>$basedir/test</testSourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>

<configuration>
<source>1.7</source>
<target>1.7</target>
<excludes>
<exclude>**/test/**</exclude>
</excludes>
</configuration>


</plugin>

</plugins>
</build>


but when i run maven install and open the generated jar the folder test is in there...
how can i solve and make it ignore this folder?










share|improve this question

















  • 1





    <exclude>test/**</exclude>

    – Micho Rizo
    Mar 8 at 5:20













0












0








0








This is one of the most asked questions here in so... but why any answer works for me? i believe i have somehow a wrong maven structure in my project



I have a project like



basedir
|-src
|--many many many packages
|-test
|--testpackages
|-pom.xml


So my pom.xml is in the same level as src and test folders and it isn't the typical structure like java/main/ java/test... it is the root of the project folder



<build>
<sourceDirectory>$basedir/src</sourceDirectory>
<testSourceDirectory>$basedir/test</testSourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>

<configuration>
<source>1.7</source>
<target>1.7</target>
<excludes>
<exclude>**/test/**</exclude>
</excludes>
</configuration>


</plugin>

</plugins>
</build>


but when i run maven install and open the generated jar the folder test is in there...
how can i solve and make it ignore this folder?










share|improve this question














This is one of the most asked questions here in so... but why any answer works for me? i believe i have somehow a wrong maven structure in my project



I have a project like



basedir
|-src
|--many many many packages
|-test
|--testpackages
|-pom.xml


So my pom.xml is in the same level as src and test folders and it isn't the typical structure like java/main/ java/test... it is the root of the project folder



<build>
<sourceDirectory>$basedir/src</sourceDirectory>
<testSourceDirectory>$basedir/test</testSourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>

<configuration>
<source>1.7</source>
<target>1.7</target>
<excludes>
<exclude>**/test/**</exclude>
</excludes>
</configuration>


</plugin>

</plugins>
</build>


but when i run maven install and open the generated jar the folder test is in there...
how can i solve and make it ignore this folder?







java maven






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 4:33









Rafael LimaRafael Lima

517419




517419







  • 1





    <exclude>test/**</exclude>

    – Micho Rizo
    Mar 8 at 5:20












  • 1





    <exclude>test/**</exclude>

    – Micho Rizo
    Mar 8 at 5:20







1




1





<exclude>test/**</exclude>

– Micho Rizo
Mar 8 at 5:20





<exclude>test/**</exclude>

– Micho Rizo
Mar 8 at 5:20












2 Answers
2






active

oldest

votes


















1














Add -DskipTests to mvn command as a workaround. For instance:



mvn package -DskipTests





share|improve this answer























  • didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

    – Rafael Lima
    Mar 8 at 4:51











  • @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

    – Common Man
    Mar 8 at 5:45











  • @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

    – Alok Dubey
    Mar 9 at 4:28












  • @AlokDubey, you are correct.

    – Common Man
    Mar 9 at 4:30


















-1














Yes, I believe your maven project structure is not correct. Maven excludes src/test/java for packaging by default so test folder should be inside src and not in the same level as shown below:



enter image description here



For more details visit Maven doc






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%2f55056770%2fexclude-test-folder-from-maven-build%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









    1














    Add -DskipTests to mvn command as a workaround. For instance:



    mvn package -DskipTests





    share|improve this answer























    • didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

      – Rafael Lima
      Mar 8 at 4:51











    • @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

      – Common Man
      Mar 8 at 5:45











    • @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

      – Alok Dubey
      Mar 9 at 4:28












    • @AlokDubey, you are correct.

      – Common Man
      Mar 9 at 4:30















    1














    Add -DskipTests to mvn command as a workaround. For instance:



    mvn package -DskipTests





    share|improve this answer























    • didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

      – Rafael Lima
      Mar 8 at 4:51











    • @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

      – Common Man
      Mar 8 at 5:45











    • @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

      – Alok Dubey
      Mar 9 at 4:28












    • @AlokDubey, you are correct.

      – Common Man
      Mar 9 at 4:30













    1












    1








    1







    Add -DskipTests to mvn command as a workaround. For instance:



    mvn package -DskipTests





    share|improve this answer













    Add -DskipTests to mvn command as a workaround. For instance:



    mvn package -DskipTests






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 8 at 4:37









    Nilanjan BNilanjan B

    2387




    2387












    • didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

      – Rafael Lima
      Mar 8 at 4:51











    • @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

      – Common Man
      Mar 8 at 5:45











    • @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

      – Alok Dubey
      Mar 9 at 4:28












    • @AlokDubey, you are correct.

      – Common Man
      Mar 9 at 4:30

















    • didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

      – Rafael Lima
      Mar 8 at 4:51











    • @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

      – Common Man
      Mar 8 at 5:45











    • @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

      – Alok Dubey
      Mar 9 at 4:28












    • @AlokDubey, you are correct.

      – Common Man
      Mar 9 at 4:30
















    didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

    – Rafael Lima
    Mar 8 at 4:51





    didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

    – Rafael Lima
    Mar 8 at 4:51













    @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

    – Common Man
    Mar 8 at 5:45





    @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

    – Common Man
    Mar 8 at 5:45













    @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

    – Alok Dubey
    Mar 9 at 4:28






    @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

    – Alok Dubey
    Mar 9 at 4:28














    @AlokDubey, you are correct.

    – Common Man
    Mar 9 at 4:30





    @AlokDubey, you are correct.

    – Common Man
    Mar 9 at 4:30













    -1














    Yes, I believe your maven project structure is not correct. Maven excludes src/test/java for packaging by default so test folder should be inside src and not in the same level as shown below:



    enter image description here



    For more details visit Maven doc






    share|improve this answer





























      -1














      Yes, I believe your maven project structure is not correct. Maven excludes src/test/java for packaging by default so test folder should be inside src and not in the same level as shown below:



      enter image description here



      For more details visit Maven doc






      share|improve this answer



























        -1












        -1








        -1







        Yes, I believe your maven project structure is not correct. Maven excludes src/test/java for packaging by default so test folder should be inside src and not in the same level as shown below:



        enter image description here



        For more details visit Maven doc






        share|improve this answer















        Yes, I believe your maven project structure is not correct. Maven excludes src/test/java for packaging by default so test folder should be inside src and not in the same level as shown below:



        enter image description here



        For more details visit Maven doc







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 9 at 4:36

























        answered Mar 8 at 5:37









        Alok DubeyAlok Dubey

        82211




        82211



























            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%2f55056770%2fexclude-test-folder-from-maven-build%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

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved