Play Framework Project: How to include plugin from source - scala

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.

Related

Could not find or load main class in scala in intellij IDE

I have searched for this error, but the answers were for Java,
but my case is Scala. I am trying to run this project in IntelliJ IDE
sentimenAnalysis, but it throws an error. This is also the structure of the project. Class Not found
Update 1 According to answers, Adding $ at the end of the name of search class
Update 2 after adding sbt task:
Update 3
My problem was resolved by importing the project, instead of getting it directly from GitHub, probably the manual configuration that Mike Allen said could resolve the problem, but I couldn't successfully apply that.
My problem was resolved when I marked "src" folder as sources root.
Right-click on (folder) src -> Mark Directory as -> Sources Root
Probably you imported project somehow wrong. I see scala folder is not highlighted as sources.
Usually, you don't even need to setup Run configuration manually for Scala SBT project. Do you have Scala and SBT Plugins in your IDE?
You should open SBT projects through "Import project" and choose "build.sbt" file. I would also recommend enabling auto-import to install all of the dependicies.
That's how it look for me:
If you still wanna make it manually your configuration should work. That's my Run configuration that works:
You will get this error if you tried to open the project and imported it incorrectly. I would open the project like this in Intellij:
File>New> Project from Existing Source>(select) Import project from external model>
(select)sbt
click Next>Finish
To fix this issue in my project I invalidated caches and restarted:
In my case the object in the object MyObject extends App was nested, if you have it unested meaning in your scala file it's not under any other object it made it work.
Netsted caused this error in intellij:
object External {
object MyMain extends App // Could not find or load main class in scala in intellij IDE
}
While the below unested worked:
object External { }
object MyMain extends App // Worked!
Hi I solved this problem by defining the class in src package under main and by setting up the configuration as default.
Create a new project and make sure SBT is proper loaded along with Scala Library. This happens with many times, bad internet connection or failure of Scala library/SBT loading might be some of the reasons.
Best of Luck for Next Project, Happy Developers & Coders.
Had a similar problem with latest Intellij IDEA build (2022.1.1) and scala 3.1.2 - both sbt and Intellij scala projects. For me the solution was to use non-ascii path.
#SeriousDron answer helped me with my problem. You need to make sure you have Scala language installed in IntelliJ. You can do this by going to Settings > Plugins > search for "Scala". Now, it will automatically pick up your .sbt file and project.
I met the same issue, please check the whole execute command and check the configuration, make sure the compiled files path is correctly configured.
refer to my screenshot:

Scala play sbt multi projects at same folder level

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"))

Local dependency in SBT fails to compile when used. SBT and Intellij see the code

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.

How to enable sbt-scalabuff in a Play2 application?

I'm trying to use sbt-scalabuff to generate scala case class from proto file. I have added the plugin reference into plugins.sbt file of the Play project, added runtime dependencies too.
If I do not add any settings to Build.scala referring to sbt-scalabuff then I assume that will go with default settings, expecting to find the files in src/main/protobuf.
Do you know any Build.scala sample of proper settings of sbt-scalabuff?
Thanks,
Gabi
I haven't actually tested sbt-scalabuff much myself, but you can try raising an issue on the sbt-scalabuff github page.

Missing build.scala in base directory

I am trying my hands on the sbt version 12
with the tutorials from GitHub.
I installed the sbt from sbt windows installer package
but any time I run sbt, the project runs but
i cannot find the build.scala file in the base directory
rather i find a target folder in the base directory with the scala file
below is the simple scala code from github
object Hi {
def main(args: Array[String]) = println("Hi!")
}
the code is defined in a scala file.
even though the code runs but i cannot find the build.scala file.
the point is that I want to build an akka project and i believe i will have to add some configurations in the build.cala file
any idea please.
SBT uses the so called "convention over configuration" approach. This means that for a simple project no configuration is required. So if you want to configure your project use either the light configuration (just create a build.sbt file in the root directory of your project) or the full configuration (just create a build.scala file in the root/project directory of your project). Consult the "Using Akka with SBT" section at the Akka's documentation website for akka dependencies and this site for the SBT configuration. Note that there is also an excellent guide for SBT available at the SBT's website.
The build.scala file goes into your /project directory which you should create in the project root folder. Read this page of the documentation.
With regard to Akka, I would start with a template project referred to in the getting started documentation, rather than trying to build it from scratch.