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)
Related
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')
)
}
Let's say you have 2 gradle projects. The first is a multi project with 2 java sub-projects:
rootProject
:my:subProject1
:myother:subProject2
The second gradle project is a single project that includeBuild's the root project:
secondProject
includeBuild '../rootProject'
I want to make a compile dependency of :my:subProject1 into secondProject.
So basically I want to add the following to secondProject's build.gradle file:
dependency {
compile(project(':my:subProject1'))
}
When I try to do that, it returns error: Project with path ':my:subProject1' could not be found in root project 'secondProject'
I seems like I can only resolve the dependency when I do the dependency as group:artifact:version. For example: my.root.project:subProject1:1.0.0. But why would it make me do that? Why not let me access the composite build's project hierarchy?
Only one settings.gradle should exist on the root, remove all setting.gradle files in any subfolders
Define the projects on the settings.gradle file of the root folder
include ':sub1', ':sub2', ':sub3'
Add compile project(":sub1") to your build.gradle under dependencies block:
dependencies{
compile project(":sub1")
}
This is just how these composite builds work. They basically act as if you published the other project to maven local prior to including it. so this means you need to depend on the version number of the split project.
In gradle if I my project depends on another package, for example:
compile 'com.example:foo:0.82.2'
And in my javadoc, it references symbol in that package.
Then if I run javadoc task, it will say error: reference not found
I know I should add that package to class path, just like the following way to add android library
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
But how could I know the classpath for my dependency except add a hard coding path point to the gradle cache?
I have following directory structure:
D:\PROJECT
+---javaGradleProject1
+---javaGradleProject2
+---javaGradleProject3
\---AndroidProject
| build.gradle
| settings.gradle
\---AndroidModule
build.gradle
Android module depends on all of java gradle projects that are at the same level in root directory as AndroidProject.
In AndroidProject/settings.gradle I have:
include ':AndroidModule'
include 'javaGradleProject1'
project(':javaGradleProject1').projectDir = new File(rootDir, '../javaGradleProject1')
include 'javaGradleProject2'
project(':javaGradleProject2').projectDir = new File(rootDir, '../javaGradleProject2')
include 'javaGradleProject2'
project(':javaGradleProject2').projectDir = new File(rootDir, '../javaGradleProject2')
And then in AndroidProject/AndroidModule/build.gradle I have dependencies set like this:
compile project(':javaGradleProject1')
compile project(':javaGradleProject2')
compile project(':javaGradleProject3')
This structure of dependency perfectly works and project builds when I invoke
gradle build
on AndroidProject/build.gradle.
But when I try to synchronize my IntelliJ with current gradle dependency settings I receive
Error: Unable to find module with Gradle path ':javaGradleProject1'
Error: Unable to find module with Gradle path ':javaGradleProject2'
Error: Unable to find module with Gradle path ':javaGradleProject3'
and because of that my project cannot be run from Run Configurations (it does not compile at all in IDE). I was trying to add these dependencies manually by hitting F4 and module dependencies but after synchronization all of my changes are overwritten (actually, IntelliJ just removes it).
Is there anything wrong in my gradle structure?
I have tested it on IntelliJ IDEA 14.1.4 and Android Studio 1.3.
I was able to solve this by deleting the settings.gradle file from every Gradle project that I wanted to use as dependency (clearing the contents of this file was not enough).
NOTE: As I have little knowledge of Gradle and Android Studio, I cannot provide information about why the presence of this file does not allow Android Studio to include the Gradle project as a module.
Add a colon (:) before the names of your modules when you add it in settings.gradle, e.g. for the first one, change this:
include 'javaGradleProject1'
project(':javaGradleProject1').projectDir = new File(rootDir, '../javaGradleProject1')
to this:
include ':javaGradleProject1'
project(':javaGradleProject1').projectDir = new File(rootDir, '../javaGradleProject1')
Now in addition to compiling, IntelliJ / Android Studio should give you code completion.
In my case I had to change the external module name to lowercase only.
Right click project, Select
"Configure Project Subset ..."
and select your module, rebuild your project.
Tried all the available solutions, and in last I have commented the include ':app' in settings.gradle and this resolved the issue in my case
In my case non of the answers above resolved it.
Finally, I went to settings.gradle file and inside the dependencyResolutionManagement block, I changed the repositoriesMode to "PREFER_PROJECT"
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
That was all I did and it worked like magic, maybe such can help you too, you can try it out.
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.