Model project dependencies in Gradle: Add a dependent project to another project - project

I am facing the following problem. I have two Gradle projects (ProjectA and ProjectB) on the same hierarchy without any root project. Since ProjectA depends on ProjectB, I tried to model this as follows:
ProjectA's settings.gradle:
includeFlat 'ProjectB'
ProjectA's build.gradle:
dependencies {
compile project(':ProjectB')
}
However, then I am getting the following error when executing 'gradle build' on ProjectA:
* What went wrong:
A problem occurred evaluating root project 'ProjectA'.
> Could not resolve all dependencies for configuration ':compile'.
> Module version group:, module:ProjectA, version:0.0.1-SNAPSHOT, configuration:compile declares a dependency on configuration 'default' which is not declared in the module descriptor for group:ProjectA, module:ProjectB, version:unspecified
Do I have to define some kind of default configuration in ProjectB?

Do I have do defined some kind of default configuration in ProjectB?
Either that, or apply the base plugin. Many other plugins (java, groovy, scala, etc.) apply the base plugin automatically, so that you don't have to.

Related

Does It possible to use multiple common libraries in Kotlin?

I have tried to build project in gradle with 3 modules, where:
1) module1 - common module with expect classes
empty build.gradle dependencies
2) module2 - common module with expect classes and with dependency from module 1:
build.gradle dependencies: compile project(':module1')
2) module3 - jvm platform module
build.gradle dependencies: expectedBy project(':module2')
When I try to compile a project, it appears errors in compilation stage of module3, that classes from module2 couldn't find classes from module1.
Kotlin 1.2.30
Gradle 4.6
Java 1.8_161
Does It possible to use multiple common modules together in one project? And does it possible to have expect classes in each common module?
Currently, using common declarations from multiple common modules is not supported, but it is planned for future versions.
In particular, once the fix for KT-22864 is released, it will allow you to add both module1 and module2 as expectedBy dependencies to module3. There's currently no public preview build with the fix, please stay tuned for 1.2.40 EAPs.
If you really want to try it early, you can use a dev build (e.g. 1.2.40-dev-754 from the https://dl.bintray.com/kotlin/kotlin-dev Maven repository).
You can also try a dev build of the IDE plugin (from here) to make the IDE import and analyze multiple expectedBy dependencies properly (1.2.30 can only import one such dependency).
For this it's needed to have more than one expectedBy declaration, which for now is forbidden. But, as say in kotlin slack, it will be possible soon.
So, for now, it's needed to switch to version 1.2.40-dev-754 of kotlin, and then it will be possible to add second expectedBy to dependencies in build.gradle in module3:
expectedBy project(':module1')
expectedBy project(':module2')

IntelliJ gradle - unknown properties

The error:
Build file 'C:\Users\Me\Dev\project\app\build.gradle' line: 21
What went wrong:
A problem occurred evaluating root project 'app'.
Could not get unknown property 'libraries' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
inside app.gradle
dependencies{
compile libraries.my_lib
deploy libraries.my_lib
}
inside project.gradle
ext.libraries = {
my_lib: 'com.myCompany:my-lib:1.0.0'
}
inside pom.xml
<modules>
<module>my-lib</modules>
</modules>
Pressing CTRL+Space in app.gradle's libaries. shows the my_lib library that may be autocompleted, but when compiling using gradle clean deploy, it fails and returns the message above.
This only happened after I updated the IDE to the latest IntelliJ.
ext defines extensions only for a project it was called in. In your case, libraries.my_lib is defined in project.gradle (I guess, it is build.gradle in project directory) and, thus, is not available in a different build file (app.gradle, which is again, I guess, is a build.gradle in app directory)) unless project is not a parent of app. Child projects have access to parent's properties, and that is the only way to share ext: projects should be related to each other.
BTW, you can define properties in gradle.properties file. There may be many of them, one for every project in your build. Placing one gradle.properties in the root of your build you apply its content to the root of your project tree, thus, making the properties available everywhere (the same applies to ext block of a root object, as it follows from the previous paragraph).

Idea not recognizing thrift types from another module in same gradle project

I have the following project structure
datatypes/
build.gradle
src/main/thrift/service.thrift
service/
build.gradle
/src/main/java/ServiceImpl.java
build.gradle
settings.gradle
I am using yodle/gradle as a gradle plugin to generate java sources from thrift and compiling those. The sources and jar files are being generated in datatypes as expected.
in service/build.gradle, I have a dependency defined as:
dependencies {
compile project(':datatypes')
}
Running gradle build works perfectly fine; my only issue is while working in idea. After importing this as gradle module, I can't get the types defined in thrift to be recognized in ServiceImpl.java.
How do I get idea to include the jar in datatypes/build/libs/ as dependency for service?
Thanks!
The issue really is that the default thrift generated java source path set by yodle/griddle plugin is inside the build/ folder. I just added the following in my datatypes/build.gradle
thriftGenDir = 'src/main'
and now the java code is generated in src/main/gen-java which is picked up as source for dataypes by idea, and uses it to define types for anyone who depends on datatypes.

get oozie-client dependency with Gradle build

I'm trying to build my project using IntelliJ and gradle. I have a dependency on oozie-client jar.
I defined the dependency in gradle as follows:
dependencies {
compile 'com.yahoo.oozie:oozie-core:3.0.0'
}
when I run buildDependency I get the following error:
* What went wrong:
Could not resolve all dependencies for configuration ':compile'.
Could not resolve com.yahoo.oozie:oozie-core:3.0.0.
Required by:
:TestRunnerFramework:1.0
Could not resolve com.yahoo.oozie:oozie-core:3.0.0.
Could not parse POM http://repo1.maven.org/maven2/com/yahoo/oozie/oozie-core/3.0.0/oozie-core-3.0.0.pom
Could not find any version that matches com.yahoo.oozie:oozie-main:3.0.0.
please advice,
This is either an incorrect POM (or incorrect parent POM), or a POM that Gradle fails to interpret correctly (there are a few known limitations around this). Often, the only solution is to edit the POM, for example in your binary artifact repository. If you think the problem is on Gradle's side, you can file an issue over at http://forums.gradle.org.

maven m2eclipse multi module project

I have a multi module maven project and the directory structure is hierarchical. Some modules have dependencies on others. I have added the dependent modules to the dependency section of the project's POM. However, in order to resolve those dependencies, I need to import the parent project, and select Project Properties > Maven and select "Enabled Modules." Is this normal? Why wouldn't the project just resolve the dependent project in the workspace?
thanks,
Jeff
However, in order to resolve those dependencies, I need to import the parent project, and select Project Properties > Maven and select "Enabled Modules." Is this normal?
No. When you import your projects, unfold the Advanced part and make sure that Resolve Workspace projects is checked (that should be the default though).
You can also change this setting at the project level. Just right-click on a project, select Properties > Maven and verify that Resolve dependencies from Workspace projects is checked.
UPDATE: Answering a question asked in a comment by the OP. From https://docs.sonatype.org/display/M2ECLIPSE/Dependency+Management about Include modules:
When enabled, dependencies from all nested modules are added to the "Maven Dependencies" container and source folders from nested modules are added to the current project build path when running "Update Sources" action. This option is enabled when you import multiple Maven projects as single Eclipse project, e.g. when "Separate projects for modules" option is turned off in the project import wizards.