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?

0
9 comments

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
Avatar
Permanently deleted user

What would you need to know?

0

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

0
Avatar
Permanently deleted user

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
Avatar
Permanently deleted user

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

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

1
Avatar
Permanently deleted user

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

0

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

0
Avatar
Permanently deleted user

@Serge : submitted a ticket --- please see --  https://intellij-support.jetbrains.com/hc/en-us/requests/2044771 

0

Please sign in to leave a comment.