Java – SBT build, run the main class of the subproject on compile and run
I have a simple build tool multi project problem
I have the following directory structure to represent my java SBT project:
/project1 /project2 /project3
So all projects share a common direct parent folder Project 1 build Items 2 and 3 are referenced in the SBT as follows:
.dependsOn(project2,project3) .aggregate(project2,project3) lazy val project2 = ProjectRef(file("../project2"),"project2") lazy val project3 = ProjectRef(file("../project3"),"project3")
In this way, there are dependencies between project1 and others
So far everything has been fine and everything is normal
But now I want to execute the main method from project2 before doing anything else When I execute the "run" task from the parent (project1), I want a specific class in project2 to execute its main methods What should I do? The SBT document explains that "aggregation means that running a task on the aggregation project will also run it on the aggregation project": http://www.scala-sbt.org/0.13.5/docs/Getting-Started/Multi-Project.html#aggregation
I didn't see my main courses on projet 2 implemented I also added it to project 2's build In SBT:
mainClass in (Compile,run) := Some("Main")
The goal of this project is to generate code at compile time and runtime Project 2's job is to generate Java and JavaScript code You can build before building other projects
Is that possible? If not, I will have to run project 2 independently of other projects
=]
Solution
If I have the following structure:
Root – back – front
And a similar http://www.scala-sbt.org/0.13/docs/Multi-Project.html As shown in build SBT project, let's say:
lazy val commonSettings = Seq( version := "0.1.0-SNAPSHOT",scalaVersion := "2.12.1",resolvers := allResolvers,libraryDependencies := AllLibraryDependencies ) lazy val client = (project in file("client")). // .enablePlugins(PlayScala) settings(commonSettings: _*). settings( name := "client" ) .aggregate(common,frontend,backend) .dependsOn(common,backend) lazy val common = (project in file("common")). settings(commonSettings: _*). settings( name := "common" ) lazy val frontend = (project in file("frontend")). settings(commonSettings: _*). settings( name := "frontend" ) .aggregate(common) .dependsOn(common) lazy val backend = (project in file("backend")). settings(commonSettings: _*). settings( name := "backend" ) .aggregate(common) .dependsOn(common)
`
Then execute a class in the front-end project. This command is useful to me:
sbt“frontend / runMain sample.cluster.transformation.frontend.TransformationFrontendApp 2551”