Project source folders change automatically with Maven

Answered

Every time I add a new Maven dependency and it is automatically downloaded and added to the project libraries, the project sources folder change and the "src" folder is marked as the one and only source project. I don't want that. I usually unmark this folder and mark the src/main/java and src/test/java folder as sources folder because I don't want my packages name to have main.java or test.java prepended.

It is quite annoying having to do this process all over again when including a new Maven dependency. How can I avoid it?

9 comments
Comment actions Permalink

With a Maven project imported from pom.xml src/main/java and src/test/java will be automatically marked as sources and test sources. If it's not the case, please share the sample project to reproduce the problem.

0
Comment actions Permalink

What would you need to know?

0
Comment actions Permalink

Share a sample with pom.xml that after importing marks wrong directories as sources.

0
Comment actions Permalink

Here it is:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>EventScheduler</groupId>
<artifactId>EventScheduler</artifactId>
<version>0.0.1-SNAPSHOT</version>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.choco-solver</groupId>
<artifactId>choco-solver</artifactId>
<version>3.3.3-j7</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.4</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.22.2</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.23</version>
</dependency>

</dependencies>
</project>
0
Comment actions Permalink

Well I just tried again. I deleted a dependecy and automatically "src" was marked as the source not the "java" folders and it messed up with the packages again.

0
Comment actions Permalink

Your pom.xml overrides Maven source root defaults with this line:

<sourceDirectory>src</sourceDirectory>

Remove this line and refresh the project.

See https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

0
Comment actions Permalink

Hi @Serge Getting the same issue .. Just with GRADLE. Can you please help me on this ? 

0
Comment actions Permalink

Submit a ticket to support with your build.gradle attached.

0

Please sign in to leave a comment.