I'm working on 2 projects in Eclipse on Windows. They're kept in their own separate folders. Their folders are located here:
W:\scala\eclipse\sdtcore
W:\scala\eclipse\sdttools
The development effort for these two projects are ongoing and therefore I haven't made JARs for them. I prefer to continue developing in Eclipse.
What I'd like is to include these two projects / their source code in a Scala Play Play project. At the moment I've tried using Typesafe Activator to generate a Play project, but I simply cannot modify the build.sbt file in a satisfactory way which can get this to work. In time I'd also prefer developing in Eclipse, but for now I can live with a simple text editor (it seems somewhat buggy/not straightforward getting it to work in Eclipse - or IntelliJ for that matter).
I'd prefer to keep my Play project in this folder for now:
W:\scala\practice\play
I am somewhat new to both Play and SBT, but have gone through some tutorials regarding SBT and subprojects and got it work - however not with a project structure like the one described. Instead I've ran against the wall with error messages complaining that my subprojects to not belong to the root folder of the project.
Can it be done? How should I go about? Simpliest, easiest course of action.
See the documentation here: http://www.scala-sbt.org/0.13/docs/Multi-Project.html
In the build.sbt of the play project try:
lazy val playProj = (project in file("."))
.dependsOn(stdcore)
.dependsOn(sdttools)
lazy val stdcore = (project in file("W:\scala\eclipse\sdtcore")) // I am not sure for the path though as I have no windows machine to try at hand
lazy val sdttools = (project in file("W:\scala\eclipse\sdttools"))
Related
I'm following up on this question, as it helped me get my "common" project recognized, but i'm not able to use it.
How to reference external sbt project from another sbt project?
Project structure
/src/services/api/project
build.sbt contains all dependencies, plus dependsOn(commonlib)
/src/commonlib/project
build.sbt is very minimal, just basic definitions.
SBT loads everything fine, when i click on the object i'm trying to use it opens in intellij and import commonlib.conversions.SomeConversion is recognized (by Intellij and clickable to my local copy).
api - sbt
lay val project = Project( id = "company", file("."), settings)
.enablePlugins(JettyPlugin)
.dependsOn(commonlib)
lazy val commonlib = RootProject(file("../../commonlib"))
commonlib is also an SBT project with /src/commonlib/src/main/scala/commonlib
in the main project i'm importing
import commonlib.conversions.SomeConversion
...
val converted = SomeConversion.convert(x)
I get a comple error stating:
not found: object commonlib
The top of the commonlib.conversions looks like
package commonlib.conversions
Any help is greatly appreciated. I may be headed down the wrong path entirely and could likely solve this with git subrepos, but i'm looking to share this across multiple projects hence the (slightly) made up name. And ultimately understand the import/sbt system better. I don't want this to be a remote jar as i'll be editing as much as the api package.
Thanks!
Taking advice from #marios i used the sbt docs, which i was working off, but his advice and github link forced me to dig a bit further.
Ultimately the commonlib project is defined inside of the api project like:
lazy val coreLib = RootProject(file("../../commonlib"))
And at the end of the api project definition in its build.sbt i have attached
.dependsOn(coreLib)
Which is nearly what i had above and tweak or two, plus cleaning my Intellij cache very likely helped.
I'm trying to import any Play project (usually from activator) into IntelliJ and each time I end up with Controllers not being resolved, i.e. you go to conf/routes and routes.ApplicationController shows up red and inside any Controller completion for routes. shows no controllers.
The projects do compile in, and even run from IntelliJ, but compiled routes just aren't picked up.
I don't know if it's related, but on project load I always get the following message:
SBT compilation for play framework 2.x disabled by default
But even if I go into the Languages & Frameworks setup and tell it to use the Play 2 compiler, the routes are not affected.
Hüseyin Zengin is right. The activator plugin which generates the .idea directory and metadata is no longer 'the way'.
The truth is it doesn't work perfectly out of the box and your best bet is to get on the latest versions of all three. This means using the Early Access Program version of Intellij.
This largely depends on the versions of Play!, Intellij and the Scala (formerly Play) plugin.
If you can't do that or still get the problem anyway then following these steps might help:
Open your Play! 2.x project in Intellij
Open Module Settings F4
In the Root Source Settings navigate the directory structure.
Add the main directory at
target/scala-/routes/main
to the Source Folders list. Right clicking the main folder and selecting Sources is one way to do this.
I'm trying to add the apache commons email library to my Play project and I'm having trouble.
Firstly I have both build.sbt and plugins.sbt in my project and I'm not sure which one I should be putting the import into, does anyone know?
Also, I'm not sure why there even is the separate project module in my project, intelliJ created it as part of the project. Could anyone explain the purpose of the two separate modules and why they are there?
Thanks!
So, in sbt, you have your project. This is specified in build.sbt (or more correctly, any *.sbt file in your projects base directory). Any libraries that your applications code needs, for example, if your application needs to send emails using the commons email library, go in to the librarDependencies seeing in here.
But build.sbt itself is Scala code that needs to be compiled, but it's not part of your applications runtime. So in sbt, your projects build is a project itself, one that has to be compiled. It has its own classpath, which consists of the sbt plugins you're using, so for example, if you need a less compiler to compile your less files, that's not something that gets done at runtime, so you don't want your application code depending on that, it goes into your project builds libraryDependencies, which gets specified in project/plugins.sbt (or in fact any *.sbt in the project directory). So, once you add it there, you can use the Scala code it provides from build.sbt. IntelliJ imports this project for you so that you can have syntax highlighting and other IDE features in build.sbt.
But it doesn't stop there. How does project/plugins.sbt get compiled, where is its classpath? Well, your projects builds projects builds project is also an sbt project itself too... It keeps going down. IntelliJ stops at that point though, it doesn't keep importing these meta sbt projects because it's actually very rare to need additional sbt plugins for your projects builds projects builds project, so it just uses the same classpath as your projects build project for syntax highlighting in project/plugins.sbt.
Background:
I am in the process of integrating TypeScript into a Play Framework (2.2.6) and I am trying to use mumoshu's plugin to do so. Problem is, the plugin has problems when running "play dist" on a windows machine.
I've forked the code from GitHub in order to make some modifications to the source so I can continue using the plugin.
Question:
I have a play framework plugin in the traditional source structure:
project/build.properties
project/Build.scala
project/plugins.sbt
src/main/scala/TypeScriptPlugin
src/main/scala/TypeScriptKeys.scala
...<other code>
I'd like to include this plugin into another project but I don't really know where to start and how to hookup the settings.
From previous suggestions, I've been able to add the module to my project as follows:
// In project/Build.scala...
object ApplicationBuild extends Build{
lazy val typeScriptModule = ProjectRef(file("../../../play2-typescript"), "play2-typescript")
lazy val main = play.Project(<appName>, <appVersion>, <appDependencies>).settings(typescriptSettings: _*).dependsOn(typeScriptModule).aggregate(typeScriptModule)
}
Where typescriptSettings is defined in the other project... I think, I'm still not 100% sure what typescriptSettings IS other than adding this settings call enabled the plugin to work. This worked fine originally when I had included the plugin in the plugins.sbt file and imported the package com.github.mumoshu.play2.typescript.TypeScriptPlugin._ but now that I'm including the source and explicitly including the module, I can't just import the package... Or at least not the way I used to.
I am still new to scala/sbt and I am having difficulty finding helpful resources online. Any help would be appreciated.
Assuming in the same parent directory you have two directories:
play2-typescript: which is a clone of mumoshu's play2-typescript
play2-typescript-testapp: which is the play app in which you're testing your changes
You need to create, inside play2-typescript-testapp's project directory a file like so:
play2-typescript.sbt
val metaBuild = (project in file(".")
dependsOn ProjectRef(file("../../play2-typescript"), "play2-typescript")
)
Note:
The relative path is to the play2-typescript plugin project, and is relative to the project directory inside play2-typescript-testapp.
Change that to what is correct in your setup, and consider that you can also define it as an absolute path.
There a lots of activator template examples of this. I have a project where we followed the https://typesafe.com/activator/template/play-multidomain-auth path. Specifically, to address your question; the plugins in the root project play-multidomain-auth/project/ are accessible in the modules (play-multidomain-auth/modules/admin/, .../common, and .../web).
This example is the cleanest example I've seen in using multi-project design however that opinion is very subjective.
I hope this helps.
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.