One source file in two modules

Answered

Is there a way to have one source file in two modules? It is easy with Maven, I add the directory with the file to both modules as the source directory, however IDEA complains that this directory is already source there and cannot be here and so on, very annoyingly.

Notes: to have a file in a third module that both former modules would be dependent on is not a solution, as one module will compile the file as JVM Kotlin and the other as JS Kotlin, so it has to be a source file. Also hard link is not usable, it is on Windows (unfortunately) and it would probably work badly with Git.

1
6 comments

It should not be a problem if the file is in 2 different modules. Please share a sample project to reproduce the issue: https://uploads.jetbrains.com.

0

OK, I've uploaded some crude stub of a project, together with a screenshot showing how Idea cannot see the file commons.kt in modA module, even though mvn compile runs without any trouble. The direcotry common has been added as a context root to module modB, however adding it also to modA is not allowed in Idea.

Upload ID: 2021_04_01_3LWBf1SQAEecVfEF

0

The mvn compile runs OK in both modules (or for the parent).

0

I can't reproduce it in 2020.3.3 release. See if deleting the System directory: https://www.jetbrains.com/help/idea/tuning-the-ide.html#system-directory helps when IntelliJ IDEA is not running.

0

No, it didn't help (also 2020.3.3, now on Linux, but originally this problem emerged in my job on Windows, to me and a colleague). Is there a way to tell Idea to prefer Maven over its own Project Structure settings? Or how comes your Idea is seeing the content of the common directory from files in modA even though it is not a (nor under) a context root for the module?

0

Ah, just solved it! I mustn't  add the common directory as a content root into the modules, rather make it a third module (unconfigured as to JVM vs JS) and add it as a module dependency to both the existing ones.

1

Please sign in to leave a comment.