How to initialize a new Scala project in sbt, Eclipse and github

后端 未结 2 641
太阳男子
太阳男子 2021-01-31 04:42

How to initialize a new Scala project in sbt, Eclipse and github, so that it all plays together...

相关标签:
2条回答
  • 2021-01-31 05:36

    A new Scala project typically requires being set up for sbt, eclipse (if you so choose) and github such that it all works together. After investing some time on this setup, it may help to have this list for aligning these 3 tools/services, for as long as simpler ways are not available. The series of steps that works for me follows. It assumes you have the Scala IDE plugin installed in eclipse.

    1. Create a new repo in Github.
    2. Decide a directory location for the new project
    3. In eclipse, use the Git Repositories View to import the Github repo into that location. Alternatively you can use command line git for that.
    4. Locate to that same location you've chosen for the project and run sbt eclipse. This makes sure eclipse will be able to handle the sbt project structure, so that your project can be built by sbt while also being intelligible for eclipse. If sbt eclipse doesn't work, the sbt eclipse plugin is probably not installed in sbt - install it.
    5. In eclipse, use File --> Import --> General --> Existing Projects into Workspace, selecting that same location, so that eclipse builds its project structure for the file structure having just been prepared by sbt.
    6. Make git ignore all but the core of your new project by updating the .gitignore file to ignore eclipse and sbt files. The following seems to be currently fine.

      *.class
      *.log
      
      # sbt specific
      dist/*
      target/
      lib_managed/
      src_managed/
      project/boot/
      project/plugins/project/
      
      # Scala-IDE specific
      .scala_dependencies
      
      # Eclipse specific
      .project
      .classpath
      .cache
      

    You should now be able to run the project in eclipse, and in sbt, and commit and push code changes through git. To see the empty project run, which may very well make sense at this stage, you can add a scala class in eclipse to it, containing merely the following code. Note that scala sources should typically sit under src/main/scala. If this path doesn't exist yet, create it through e.g. mkdir -p src/main/scala on Unix.

    object hello {
      def main(args: Array[String]) {
        println("Main starting")  
      }
    }
    

    Or alternatively only this code:

    object app extends App {
      println("Application starting")  
    }
    

    It should work now. Need to disclaim that future versions of eclipse, sbt, etc may render this outdated. If this is dead wrong in your environment, you can add a better answer.

    0 讨论(0)
  • 2021-01-31 05:43

    Previous answer/s is/are of high importance as well as the question since these tools are not self explanatory. Based on personal experience with this challenge which seemed impossible but when one acknowledges few key insurance policy reference points things will become reality:

    1. Implementation of development environment may require radical re-installation as new tool is adopted (if you adopt GIT after you already had SBT in place you may need to empty SBT's working directory as GIT require the cloning process to have empty house on local working directory)
    2. Keep really well updated backups especially when considering re-setting any of this "domino" environment layers as some of the GUI or command initiated cleansing operations truly take care of that sometimes with surprising effectiveness and without any regard to other tools / layers requirements
    3. Keep really good documentation (including previous pragmatic answer) on key stages to make things a reality (again)
    0 讨论(0)
提交回复
热议问题