How to initialize a new Scala project in sbt, Eclipse and github, so that it all plays together...
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.
Create a new repo in Github.
Decide a directory location for the new project
In eclipse, use the Git Repositories View to import the Github repo into that location. Alternatively you can use command line git for that.
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.
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.
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.
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:
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)
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
Keep really good documentation (including previous pragmatic answer) on key stages to
make things a reality (again)
Related
I want to import a maven project from GitHub into intellij which in of itself I know how to do however, the project this time was created initially also as an eclipse project and I want to be able to work on it in idea while my team members work on it in eclipse without causing conflicts due to differing project file structures. How can this be done?
When checking it out in Intellij it does ask me if I want to create a project from it and select yes but next, it asks whether to create the project from the existing sources vs from external model. From the external model option it allows me to pick eclipse or maven but not both. Do I just create from existing sources? Which is my best option to do this without screwing it up for the others when I commit and push my changes?
I understand that the easy answer might be: "just use eclipse" however, I think the answer on how to properly do this could be useful later. Not only me but also for others who want to work with the IDE they are most familiar and productive with and not mess with the workflow.
Any help would be appreciated
When importing an Eclipse project into IntelliJ, you have the option to:
Create module files near .classpath files
Keep project and module files in
The idea is to keep your *.iml file concurrently with your Eclipse .project/.classpath (and you can keep them in sync).
That way, you can open the project in both IDE.
Is there a definite doc somewhere that explains all the magic that happens behind the "Typesafe Activator" generation of "IntelliJ supported" project?
The sbt build files look absolutely monstrous, and I have no idea what and where IntelliJ looks for.
This is frustrating as working from two different PCs the scala seed project refers to different hard-coded paths.
Is there a good place to start?
Last time I checked, the typesafe activator was using SBT as the underlying build tool. When creating an intellij project it would thus use the sbt-idea plugin.
I guess a possible place to start would be that plugin's documentation.
However I think there is something else going on here. I think you have the activator installed on two different PCs and are trying to share the project between both PCs whether using version control or copying the folders.
The sbt-idea plugin will indeed write some absolute path in ideas project files (most likely the absolute paths to the sbt managed libraries in the ivy cache of your home folder) since this is required for the intellij project to work.
There should be no reason to "share" the idea project files, these should be considered computer specific and should not be checked into source control, or expected to work when copied from a random computer to another. You are expected to regenerate them for each computer the project is worked on.
If that sounds like a burden, you may want to install the Intellij scala plugin. Once installed, the sbt integration will allow you to import any sbt project even if you haven't generated the intellij support in the activator. Have a look at the features page, there is a video showing how to use the plugin.
I am trying to get started with Eclipse SCADA and import the projects from their git repository.
I have cloned the following projects:
org.eclipse.scada.external
org.eclipse.scada.utils
org.eclipse.scada.base
org.eclipse.scada.protocols
org.eclipse.scada.core
org.eclipse.scada.releng
For each project I did mvn verify in the parent folder and imported the projects in Eclipse. I also changed target platform. However, I still seem to have problems with their dependencies.
Any help would really be appreciated.
Actually the Eclipse SCADA java projects are not developed with "Maven first". So you should disregard maven completely while in the IDE. The maven build is basically only used to build the project unattended.
The issue with the target platform is more complex. We were a bit sloppy in providing a always working target platform (and it is actually difficult to keep them up to date, since the versions of the bundles are fix).
I made a target platform file for the current version, you can find it here: https://gist.github.com/CptMauli/ec6eda37734f0108510f
To make it work properly please download a classic eclipse put it somewhere and create an environment variable ECLIPSE_432_HOME which points to it. Alternatively you can just change the first entry in the target file and point it directly to it.
The reason behind it is, if you would use your own eclipse installation, it is possible that bundles installed there conflict with bundles provided in the target platform or from your workspace. This is actually mostly not even a problem when compiling, but as soon as you start a client or a server, Eclipse will complain about duplicated bundles.
If you have any more questions please go to our mailing list: https://dev.eclipse.org/mailman/listinfo/scada-dev
or our google group: https://groups.google.com/forum/#!forum/openscada
or write to me directly at juergen dot rose at ibh-systems dot com
I had a package structure which I changed, and this lead to the corresponding folders in /bin/ being removed, so now I get a ClassNotFoundException.
More specifically, I had the ususal /src/ and /bin/, and inside /src/ I had /main and /test, and this was presumably mirrored in /bin/. I shuffled the files around a bit and ended up with /main/model/ and /test/model/.
I have tried to manually create the corresponding folders (mirroring the packages in /src/), but this does not seem to help. I managed to compile the classes in one of the packages, but not in the test package, since it uses ScalaTest* and I didn't manage to compile the classes with the scalatest jar file (or something was wrong with the classpath).
So my question is:
How do I fix this within this peoject? (I don't want to simply create a new project and copy the source files over)
I'm guessing that I should learn more about build systems to be more resilient to such annoyances in the future? If so, what should I read up on, specifically to become better at troubleshooting and having more fine grained control over the build in the context of IDEs in the future (making builds independent of IDEs is not a priority for me at this point)?
An answer to one of these questions would be sufficient.
*All the source files are .scala files, if that might matter.
Udate
I did a clean of the project (project -> clean). This seemed to fix the problem: I was able to run the test classes from within Eclipse. All the binary files were in there, too. I made a new package, main.controller, with one class, and when I tried to run it, it said that it couldn't find the class. I tried to run the tests again, but those gave me a ClassNotFoundException, too. When I looked in /bin/ it turned out that all the folders and files were gone. I've tried to clean the project again but to no avail. I don't understand how I was able to clean the project, but now it can't fix it?
Update 2
To test if this was reproducible with a Java project, I made a Java project with two packages; main and test. I had the main class in main, which used a class from test (so there were dependencies across the packages). It ran succesfully. Then I added packages so that I had main.model and test.model and moved the corresponding files there. It also ran. Then I tried to delete all the files and folders in /bin/, and then the main class would not run. But if I did a clean of the project, then it cleaned it succesfully and the Main class was able to run. Then I made a Git repository for it, placing it outside of /workspace/ (in my git folder) and tried to do the same there. Eclipse was able to clean the project succesfully everytime.
So I don't understand why it can't manage to clean my Scala project.
I had errors in the "Problems" tab (Window -> Show View -> Problems). Now that I've made them go away, my /bin/ is correct and I can run both my Main class and my tests. This Question helped find out what the problem was:
Scala project won't compile in Eclipse; "Could not find the main class."
I work for a small company of software consultants, that does development primarily (currently: solely) for the JVM using Eclipse as our IDE of choice.
Until now, we have not been using any Project Management/Build Tools. We have used a company SVN repository for version control of our projects along with any binary dependencies (well JAR dependencies) of same. This has gotten a bit messy, and we have a lot of extraneous *.jar files in lib folders across our projects.
With our recent shift to Scala as our PL of choice, we have also looked into using SBT as build tool. We have set up a Sonatype Nexus repository, and have begun declaring SBT files for our projects
The thing is, that we have a set of utility projects that are used across a lot of projects for our customers. Until now, we have managed inter-project dependencies by having an Eclipse workspace for each customer project, with each of these having a local version of the utility projects on which it has dependencies. Keeping local versions up to date has therefore been handled solely through SVN commits and updates.
I guess that there are a couple of different ways that we could go about structuring our projects and workspaces. Using SBT to define inter-project dependencies, it would make sense to have a workspace for the utility projects alone, and then importing snapshots/releases as managed dependencies in our customer projects. However, since we often make enhancements to the utility projects during development of the customer projects, it would be nice to still be able to do this in the same workspace and as much on the fly as possible.
From: http://www.devdaily.com/scala/using-github-projects-scala-library-dependencies-sbt-sbteclipse it seems that a plugin exists for Git that grabs current versions from a Git repository, builds the source and includes them in the Eclipse classpath. This sort of setup would allow us to continue to use the revision control system as the main means of distributing project updates, though I have not been able to find something similar for SVN...
Is anyone using SBT with SVN and eclipse, and/or knows of a smart way to setup interproject dependencies without firing a lot of publish/publish-locals alongside the SVN commands?
It would be nice to somehow declare interproject dependencies using SBT, since this would allow us to dump the responsibility for transient managed dependencies on SBT...