Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src/main folders, etc interpreted as a package names #201

Closed
bbarker opened this issue Mar 5, 2018 · 4 comments · Fixed by #298
Closed

src/main folders, etc interpreted as a package names #201

bbarker opened this issue Mar 5, 2018 · 4 comments · Fixed by #298
Assignees
Labels
good-first-issue The fix/solution for the issue is considered easy. A good starting point for newbies. solved The issue was fixed/resolved
Milestone

Comments

@bbarker
Copy link
Contributor

bbarker commented Mar 5, 2018

When intellij project files are regenerated, it seems to set src as the sources root, and not e.g. src/main/scala, which makes all new packages created have a prefix of main.scala.whatever....

@lihaoyi
Copy link
Member

lihaoyi commented Mar 5, 2018

Yeah IntelliJ project generation should probably put the source root as src/main/scala/.

This only applies to the SbtModule, normal ScalaModule isn't affected

@lihaoyi lihaoyi changed the title src/main folders, etc interpreted as a package games src/main folders, etc interpreted as a package names Mar 5, 2018
@lihaoyi lihaoyi added the good-first-issue The fix/solution for the issue is considered easy. A good starting point for newbies. label Mar 5, 2018
@lvauthrin
Copy link

lvauthrin commented Mar 20, 2018

I'm trying to see if I can pickup this task but I'm not sure what is wrong. I changed GenIdeaTests.scala to use an SbtModule and that required me to update the test resource file to use src/main/scala (which I think is expected behavior).

I then created a couple minimal projects (one ScalaModule and one SbtModule) and both seem to be imported by IntelliJ correctly.

Module output for build that extends ScalaModule:

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager">
    <output url="file://$MODULE_DIR$/../out/foo/compile/dest/classes" />
    <exclude-output />
    <content url="file://$MODULE_DIR$/../foo">
      <sourceFolder url="file://$MODULE_DIR$/../foo/src" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/../foo/resources" type="java-resource" />
      <excludeFolder url="file://$MODULE_DIR$/../foo/target" />
    </content>
    <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" name="scala-sdk-2.12.4" level="application" />
    <orderEntry type="library" name="scala-library-2.12.4-sources.jar" level="project" />
    <orderEntry type="library" name="scala-library-2.12.4.jar" level="project" />
  </component>
</module>

Module output for build that extends SbtModule:

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager">
    <output url="file://$MODULE_DIR$/../out/foo/compile/dest/classes" />
    <exclude-output />
    <content url="file://$MODULE_DIR$/../foo">
      <sourceFolder url="file://$MODULE_DIR$/../foo/src/main/java" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/../foo/src/main/scala" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/../foo/src/main/resources" type="java-resource" />
      <excludeFolder url="file://$MODULE_DIR$/../foo/target" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" name="scala-sdk-2.12.4" level="application" />
    <orderEntry type="library" name="scala-library-2.12.4-sources.jar" level="project" />
    <orderEntry type="library" name="scala-library-2.12.4.jar" level="project" />
  </component>
</module

What am I missing?

@rockjam rockjam self-assigned this Mar 31, 2018
@Krever
Copy link

Krever commented Apr 13, 2018

Can't say how related this is but I use sbt project layout and spotted an issue with directories marking.
I have a setup very similar to the following:

trait MyModule extends SbtModule
 
object algebras extends Module {

  object algebra extends mill.Cross[AlgebraModule](`scala 2.10 to 2.12`: _*)

  object algebraCirce extends mill.Cross[AlgebraCirceModule](`scala 2.10 to 2.12`: _*)

  class AlgebraModule(val crossVersion: String) extends MyModule {
    object test extends Tests
  }

  class AlgebraCirceModule(val crossVersion: String) extends MyModule {
    object test extends Tests with EndpointsTests
  }
}

And the outcome of modules generation is presented like this:
ss
Because each directory is a home for two modules(normal and test) idea seems to be lost in presenting them properly. As we can see in the picture, it chooses randomly which module to take and present, so sometimes tests works fine and sometimes main.

Modules itself are generated correctly, they just don't interoperate with each other. Unfortunately, I have no idea if or how it can be fixed.

Sample:

<module type="JAVA_MODULE" version="4">
    <component name="NewModuleRootManager">
        <output url="file://$MODULE_DIR$/../out/algebras/algebra/2.12.4/compile/dest/classes"/>
        <exclude-output/>
        <content url="file://$MODULE_DIR$/../out/algebras/algebra/2.12.4/generatedSources/dest"/>
        <content url="file://$MODULE_DIR$/../algebras/algebra">
            <sourceFolder url="file://$MODULE_DIR$/../algebras/algebra/src/main/java" isTestSource="false"/>
            <sourceFolder url="file://$MODULE_DIR$/../algebras/algebra/src/main/scala" isTestSource="false"/>
            <sourceFolder url="file://$MODULE_DIR$/../algebras/algebra/src/main/resources" isTestSource="false" type="java-resource"/>
            <excludeFolder url="file://$MODULE_DIR$/../algebras/algebra/target"/>
        </content>
        <orderEntry type="inheritedJdk"/>
        <orderEntry type="sourceFolder" forTests="false"/>
        <orderEntry type="library" name="scala-sdk-2.12.4" level="application"/>
        <orderEntry type="library" name="scala-library-2.12.4-sources.jar" level="project"/>
        <orderEntry type="library" name="scala-library-2.12.4.jar" level="project"/>
    </component>
</module>
<module type="JAVA_MODULE" version="4">
    <component name="NewModuleRootManager">
        <output url="file://$MODULE_DIR$/../out/algebras/algebra/2.12.4/test/compile/dest/classes"/>
        <exclude-output/>
        <content url="file://$MODULE_DIR$/../out/algebras/algebra/2.12.4/test/generatedSources/dest"/>
        <content url="file://$MODULE_DIR$/../algebras/algebra">
            <sourceFolder url="file://$MODULE_DIR$/../algebras/algebra/src/test/java" isTestSource="false"/>
            <sourceFolder url="file://$MODULE_DIR$/../algebras/algebra/src/test/scala" isTestSource="false"/>
            <sourceFolder url="file://$MODULE_DIR$/../algebras/algebra/src/test/resources" isTestSource="false" type="java-resource"/>
            <excludeFolder url="file://$MODULE_DIR$/../algebras/algebra/target"/>
        </content>
        <orderEntry type="inheritedJdk"/>
        <orderEntry type="sourceFolder" forTests="false"/>
        <orderEntry type="library" name="scala-sdk-2.12.4" level="application"/>
        <orderEntry type="library" name="accessors-smart-1.1-sources.jar" level="project"/>
        <orderEntry type="module" module-name="algebras.algebra-2.12.4" exported=""/>
    </component>
</module>

EDIT

I fixed it by moving test modules roots into src/test directories:

def genidea(ev: Evaluator[Any]) = T.command {
  mill.scalalib.GenIdeaImpl(
    implicitly,
    ev.rootModule,
    ev.rootModule.millDiscover
  )
  import ammonite.ops._
  val files = (ls ! pwd / ".idea_modules")
    .filter(_.toString().endsWith("test.iml"))
  files.foreach { file =>
    val content = read(file)
    val regex = """<content url="file://\$MODULE_DIR\$/\.\./(.*)">""".r
    val replacement = """<content url="file://\$MODULE_DIR\$/\.\./$1/src/test">"""
    val newContent = regex.replaceFirstIn(content, replacement)
    write.over(file, newContent)
  }
}

@rockjam
Copy link
Collaborator

rockjam commented Apr 15, 2018

@Krever probably this is right thing to do. Will fix it in master

rockjam added a commit to rockjam/mill that referenced this issue Apr 15, 2018
rockjam added a commit that referenced this issue Apr 19, 2018
* mark test module as test sources

* add test case for test module in GenIdea

* fixes #201 change mill project path for sbt and maven tests
@lefou lefou added this to the 0.2.1 milestone May 2, 2019
@lefou lefou added the solved The issue was fixed/resolved label Jul 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-first-issue The fix/solution for the issue is considered easy. A good starting point for newbies. solved The issue was fixed/resolved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants