Play Framework 2.2 subprojects - java

I'm trying to add a subproject to my Play Framework project, and find the docs generally lacking there.
I've created a play project, let's call it my-web, and it's in directory /my-cool-project/web. I also have another project I would like my-web to depend on, let's call it my-model. my-model a git submodule for my-cool-project, and when I pull it, my directory structure is
/my-cool-project
/my-web
/app
/conf
build.sbt
/my-model
/main
/java
/src
Now, how do I add my-model as a subproject for my-web? I've tried
lazy val myModel = project.in(file("../my-model"))
but all I get is that my-model is not contained within the build root of my-web... Anything else I can try in build.sbt?

project is used to define the project model and sub-projects. For sibling project, you can use RootProject or ProjectRef. In your case, I would use RootProject.
lazy val myModel = RootProject(file("../my-model"))
When you compile a project, compilation on all RootProjects and ProjectRefs will triggered as well. You will define your project setting for my-model inside the build file in my-model project. This reduce the duplication for the project definition.
Think about RootProject and ProjectRef like project reference in Eclipse.
Let me know if this is what you are looking for.

change lazy val myModel = project.in(file("../my-model"))
to
lazy val myModel = project.in(file("my-model"))
Path it refers is from root of the project. So, you can give this path accordingly.

Related

Gradle nested projects setup

How do I set up such a project structure where I have the root project called "app", "frontend" and "backend" project inside and a count of library projects inside each. Then run a build task that would give me one backend jar and a swing (for example) jar application.
Like this:
root (App)
frontend
library
main
backend
library
main
then run: gradle build and have build/.../frontend.jar and build/.../backend.jar
I did try using include inside settings.gradle but that doesn't seem to work (at least gradle projects and intellij idea do not recognise the projects inside frontend and backend). I had:
root/settings.gradle with: include 'frontend', 'backend'
root/backend/settings.gradle with: include 'library', 'main'
and the same for frontend
There are multiple ways. one way at the root settings.gradle (gradle v7.1)
rootProject.name = 'test-prj-tree'
include 'backend'
include 'frontend'
include 'library'
include 'backend:library'
findProject(':backend:library')?.name = 'backend-lib'
include 'backend:main'
findProject(':backend:main')?.name = 'backend-main'
include 'frontend:library'
findProject(':frontend:library')?.name = 'frontend-lib'
include 'frontend:main'
findProject(':frontend:main')?.name = 'frontend-main'
In modern Gradle it's possible to includeBuild, which solves the problem perfeclty:
// root/settings.gradle.kts
rootProject.name = "root"
includeBuild("backend")
includeBuild("frontend")
// root/backend/settings.gradle.kts and root/frontend/settings.gradle.kts
include(":library")
include(":main")

IntelliJ / Gradle - composite build project - how to import from different module?

I'm new to Java and am currently trying to build a cucumber / selenium project in IntelliJ that contains two modules: A library project containing page definitions, and a test project that contains the cucumber features and step definitions that talk to those page definitions. The idea is that the page definitions are a shared resource, and the tests are specific to different projects / groups. Both modules are at the same level underneath the parent project. The build is using Gradle, and the settings.gradle file for the parent looks as follows:
rootProject.name = 'composite-builds'
includeBuild 'libraryproject'
includeBuild 'testproject'
Using Gradle includeBuild on the parent project works fine and the whole project imports. However I am having no luck using the library project in my import statements in the test project. It consistently returns me these kinds of error: java: package libraryproject.pageFactory.examplePages does not exist and is clearly not seeing the library module.
What do I need to do / add in order for the test project to recognise the library project? I did try to also add the includeBuild statement in the settings.gradle for the test project but this made no difference.
The library can be found here
Update: the real reason that I cannot see the modules from the library project is that they were held in the test folder, not main.
Go to your build.gradle file
Instead of includeBuild use dependencies{compile{project(':libraryproject')}}
Inside the Root Project of libraryproject which is in your case the composite-builds. Change includeBuild to include in the settings.gradle
rootProject.name = 'composite-builds'
include ':libraryproject'
include ':testproject'
If it is in the same root:
dependencies {
compile(
project(':libraryproject')
)
}
Subfolder:
dependencies {
compile(
project(':myFolder1:myFolder2:libraryproject')
)
}

Gradle nested project configuration

I'm a bit confused about setting up the build script for a nested project
I've written a simple test repo here https://github.com/814k31/TestGradle
Essentially I am writing a wrapper for a module and need that wrapper to be included in a larger project, however I'm having trouble importing the module in the wrapper when it is used within a larger project
Dependency Chain
app imports OneDeep
OneDeep imports TwoDeep
Directory structure:
app
oneDeep
twoDeep
build.gradle
build.gradle
build.gradle
settings.gradle
The master branch in the test repo is written how I should expect it to work
There is also another branch where I've tweaked the settings.gradle to work, though it feels like I shouldn't do that...
Any suggestions on how to get oneDeep (the wrapper) to import twoDeep (the module)?
Thanks in advance.
You don't describe the error you get, but if we execute your example from the master branch in your repo, we get following error:
> Project with path ':twoDeep' could not be found in project ':oneDeep'.
This problem comes from the way you reference project 'twoDeep' from project 'oneDeep' script:
dependencies {
compile project(':twoDeep') // <== this won't work: there is no project with absolute path ":twoDeep"
// compile project('twoDeep') // <== use relative path to reference sub-project 'twoDeep' from project 'oneDeep'
// compile project(':oneDeep:twoDeep') // <= using absolute path will work as well
}
So you must either use relative path ( => 'twoDeep' ) or absolute path ( => ':oneDeep:twoDeep') when referencing subproject 'twoDeep' from project 'oneDeep'.
From Project DSL documentation:
Project project(String path) :
Locates a project by path. If the path is relative, it is interpreted relative to this project.
See also Project and task paths (but it's not clearly stated there what is the expected syntax for "relative" paths)

SonarQube not apply analyzing to the root project

I need to make analyzing only root project, and ignore nested sub module, but it d
So I have this hierarchy:
ProjectMain
-src
-subProjectAngular
settings.gradle
My configuration settings.gradle
rootProject.name="ProjectMain"
include 'subProjectAngular'
I need to make analyzing only root project, and ignore nested sub module, but I got:
A multi-module project can't have source folders, so 'C:\Users\vagrant\develop-2\site\Source\Site\Vessels\src\main\java' won't be used for the analysis. If you want to analyse files of this folder, y
ou should create another sub-module and move them inside it.
Then I tried to add multi module configuration:
systemProp.sonar.projectKey=site
systemProp.sonar.projectName=vessels-test
systemProp.sonar.projectBaseDir=.
systemProp.sonar.sources=src
systemProp.sonar.modules=javamodule, angularmodule
systemProp.javamodule.sonar.projectName=vessels
systemProp.javamodule.sonar.sources=src
systemProp.javamodule.sonar.projectBaseDir=.
systemProp.javamodule.sonar.language=java
systemProp.angularmodule.sonar.projectName=angular
systemProp.angularmodule.sonar.projectBaseDir=.
systemProp.angularmodule
but got message at UI: no analysis has been performed
It's only works when I remove definishion of subproject from settings.gradle, and remove all submodule confguration
This configuration is not support yet in SonarQube.
But the good news is that this will change with SonarQube 6.4 (expect in early May 2017). See the following tickets:
SONAR-6724
SONARGRADL-5

Importing External project in Play Application

Hi I'm trying to reference my external java project in my play framework project. Lets say my structure is:
/workspace
-playProject
-javaProject
I want to be able to call classes of javaProject in my playProject. I did some research and people were suggesting to add this line to my build.sbt:
lazy val javaProject = RootProject(file("../rolosRepo"))
lazy val root = (project in file(".")).dependsOn(javaProject).enablePlugins(PlayJava)
But still it tells me that the package com.xxx.xxxx does not exist.
Note: I have included the javaProject in my playProject build path

Categories

Resources