Gradle Multiproject build dependencies: package does not exist - build

My project structure
Main_Project/
--build.gradle
--settings.gradle
--com.project.core/
----build.gradle
--com.project.core.test/
----build.gradle <--this requires classes defined in ProjectCore
Dependencies for ProjectTest build.gradle:
dependencies {
compile project(':com.project.core')
testCompile "junit:junit:4"
runtime files('C:/eclipse/plugins/org.hamcrest.core_1.3.0.v201303031735.jar')
}
Here is my settings.gradle:
include 'com.project.core',
'com.project.core.test'
Reported error message:
H:\gitwork\com.project.core.test\src\com\project\common\providable\sortedprovidablemanagertest\SimpleObject.java:8: error:
package com.project.core.providable.abstractions does not exist
import com.project.core.providable.abstractions.AProvidable;

If you want to use project names that differ from the corresponding directory names, you'll have to configure the latter separately:
include 'com.project.core'
include 'com.project.core.test'
project(':com.project.core').projectDir = 'ProjectCore'
project(':com.project.core.test').projectDir = 'ProjectTest'

Related

Some problems were found with the configuration of task ':app:generateDebugApolloIR' (type 'ApolloIRGenTask')

I've updated my gradle version to latest version and now my project is not able to build. The following errors are being shown on logcat while building project.
FAILURE: Build failed with an exception.
* What went wrong:
Some problems were found with the configuration of task ':app:generateDebugApolloIR' (type 'ApolloIRGenTask').
- In plugin 'com.amazonaws.appsync' type 'com.apollographql.apollo.gradle.ApolloIRGenTask' field 'extension' without corresponding getter has been annotated with #Internal.
Reason: Annotations on fields are only used if there's a corresponding getter for the field.
I've tried to rebuild project, clean project, invalidate caches. But still having the same issue.
My build.gradle Project Level:
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.google.gms:google-services:4.3.14'
classpath 'com.google.ar.sceneform:plugin:1.17.1'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
classpath 'com.amplifyframework:amplify-tools-gradle-plugin:1.0.1'
classpath "com.amazonaws:aws-android-sdk-appsync-gradle-plugin:3.1.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
build.gradle app level
//AWS
implementation 'com.amplifyframework:core:1.29.0' //updated
implementation 'com.amplifyframework:aws-api:1.28.3' //updated
implementation 'com.amplifyframework:aws-datastore:1.28.3' //updated
implementation 'com.amazonaws:aws-android-sdk-appsync:3.1.1' //updated
implementation 'com.amazonaws:aws-android-sdk-s3:2.35.0' //updated
Upgrade your library versions
build gradle project level
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.google.gms:google-services:4.3.14'
classpath 'com.google.ar.sceneform:plugin:1.17.1'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
classpath 'com.amplifyframework:amplify-tools-gradle-plugin:1.0.1'
classpath "com.amazonaws:aws-android-sdk-appsync-gradle-plugin:3.3.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
build gradle app level
//AWS
implementation 'com.amplifyframework:core:1.31.3' //updated 1.31.3
implementation 'com.amplifyframework:aws-api:1.28.3' //updated
implementation 'com.amplifyframework:aws-datastore:1.28.3' //updated
implementation 'com.amazonaws:aws-android-sdk-appsync:3.3.0' //updated 3.3.0
implementation 'com.amazonaws:aws-android-sdk-s3:2.40.0' //updated 2.40.0
build project now, it will work

How to use export custom target with CMake?

I'm trying to export all of the dependent targets of an engine I've been developing with export command. Everything works fine with dependencies, but when I call the command with main "Nabla" target, I get a following error:
CMake Error in CMakeLists.txt:
export called with target "Nabla" which requires target "openssl_build"
that is not in any export set.
The problem is that the openssl_build is a custom target and I have no clue how to avoid this error, because when I try to export the target I get another error telling me that
-- Using static CRT ON
CMake Error at 3rdparty/CMakeLists.txt:556 (export):
export given custom target "openssl_build" which may not be exported.
the following commit contains my changes to the engine in reference to export command
The custom target generating the error is here
I wonder if I could set a cmake property for the openssl_build to make it work, but I have been looking for useful properties in cmake docs and could not find anything
Thank you in advance!
This usually happens when you use add_subdirectory to consume library.
When you add add_subdirectory, CMake will consider, for example, the whole openssl project become part of your project. They are not separable if they are the same project.
If you build openssl as part of your project, it's very doubting that your project will run properly without also having openssl installed, let alone users consuming your package!
You could simply add the openssl libraries you depend on to the export set:
install(TARGETS openssl_build EXPORT NablaTargets)
But that's not the proper way.
The proper way would be to use a package manager, such as vcpkg to install the dependencies for you.
First, replace the add_subdirectory by a find_package and a link:
find_package(OpenSSL REQUIRED)
target_link_libraries(Nabla PUBLIC OpenSSL::SSL OpenSSL::Crypto)
Create vcpkg.json with this content:
{
"name": "nabla",
"version-string": "0.1",
"dependencies": [
"openssl"
]
}
And when you use cmake, add the argument -DCMAKE_TOOLCHAIN_FILE=/opt/vcpkg/scripts/buildsystems/vcpkg.cmake (or where you installed it) and let the package manager do the work for you.
Remember that when you use a new toolchain file, you must re-create a new build directory since it cannot be added after creating it.

Error "/usr/bin/ld: cannot find library: File format not recognized" when application is built as part of a collection of products

I have a QBS Project which is a collection of subprojects, including static libraries, shared libraries, and a Qt GUI applications. The Qt GUI application has been giving me issue in that the linking stage fails, throwing several "/usr/bin/ld: cannot find {library}: File format not recognized" errors for libraries that are built earlier in the project chain. It does not do this for all libraries though, including libraries with near identical .qbs files as those which do throw this error.
Oddly enough, if I build the application on it's own, that is to say I run qbs from within the application's project directory rather than at the top level, it builds fine (assuming the dependent libraries all exist within their install directories). The main difference I see is that when building the full project, the cpp.libraryPaths for the application are ignored for all products in the project and the application attempts to link against the lib files produced in the build directory, while when building the application on it's own the cpp.libraryPaths are used as intended, and the files in the install directory are linked against successfully.
I have no idea why the lib files in the install directory can be linked against while files in the build directory throw errors. What could be causing the linking to fail in the first place? Additionally, how can I fix my project configuration so that I can build everything by calling qbs at the top level. Am I perhaps going about this in the wrong manner?
Here is the command I use to start the build:
qbs qbs.installRoot:. release
And a visual representation of the issue:
Poject <-- calling qbs here throws errors at linking application
|- LibraryOne
|- LibraryTwo
|- Application <-- calling qbs here works if libraries already built
And here is a very simplified reproduction of the relevent qbs files
-- SubOne.qbs and SubTwo --
// These are identical excluding the files
StaticLibrary {
name: // "One" or "Two"
files: [/*Files...*/]
Depends {
name: "Qt"
submodules: [/*core, etc...*/]
}
Depends { name: "cpp" }
// cpp depends and properties
Group {
fileTagsFilter: product.type
qbs.installDir: "lib"
qbs.install: true
}
}
-- App.qbs --
QtGuiApplication {
name: "App"
files: [/*Files...*/]
Depends { name: "One" } // I comment out these depends when building the Application on it's own
Depends { name: "Two" }
Depends { name: "cpp" }
cpp.includePaths: ["../One/include","..Two/include"]
cpp.libraryPaths: ["../lib"] // <-- Ignored during full project build
cpp.staticLibraries: ["One","Two"]
Group {
fileTagsFilter: product.type
qbs.installDir: "bin"
qbs.install: true
}
}
Never run qbs from a subdirectory. You should always run it on the top-level project file. In your root directory you should have a file like this:
// project.qbs
import qbs
Project {
// order doesn't matter here
references: [
"LibraryOne/SubOne.qbs",
"LibraryTwo/SubTwo.qbs",
"Application/App.qbs"
]
}
Secondly, you should not set the cpp.libraryPaths and cpp.staticLibraries in your application, as the Depends items which you have in your application, will already handle this (never comment them out).
Your cpp.includePaths properties should also not be set in the application, instead they should go into an Export item in each of your respective static libraries, like so:
StaticLibrary {
...
Export {
Depends { name: "cpp" }
cpp.includePaths: [product.sourceDirectory + "/include"]
}
...
}
Then run qbs -f project.qbs and everything should be built correctly.

gradle not using compile time dependencies when building

Hi guys I'm new to gradle and have the following issue.
When I use the java plugin and invoke $gradle build on my project it does not put my third party dependencies on the classpath. My build.gradle file looks as follows:
apply plugin: 'java'
sourceSets.main.java.srcDirs = ["src/main/java", "src/main/web"]
repositories {
flatDir name: 'thirdParty', dirs: 'C:/dev/repo'
}
dependencies {
compile files('log4j-1.2.12.jar', 'gson-1.7.1.jar')
}
and the error output from gradle is the following
C:\dev\gradling\TestProject\src\main\web\java\org\gradle\example\simple\HelloWorld2.java:3: package com.google.gson does not exist
import com.google.gson.Gson;
^
C:\dev\gradling\TestProject\src\main\web\java\org\gradle\example\simple\HelloWorld2.java:7: cannot find symbol
symbol : class Gson
location: class org.gradle.example.simple.HelloWorld2
Gson gson = new Gson();
^
C:\dev\gradling\TestProject\src\main\web\java\org\gradle\example\simple\HelloWorld2.java:7: cannot find symbol
symbol : class Gson
location: class org.gradle.example.simple.HelloWorld2
Gson gson = new Gson();
I have stated where my repo jars live and told it that when it compiles it must include the above mentioned jars.
Please help.
Your dependency declarations are incorrect. You can either specify a flatDir repo and use the usual dependency syntax for external dependencies (group:module:version), or use the files method together with correct file paths (then you don't need to declare a repository). In the former case, you may leave out the dependency's group. For example:
repositories {
flatDir name: 'thirdParty', dirs: 'C:/dev/repo'
}
dependencies {
compile ':log4j:1.2.12'
}
For more information, consult the Gradle User Guide.

Gradle: How to make a compile scope file dependency excluded in packaging?

I have a multi-module gradle project with the following basic structure:
root
core
c-interface
m-interface
The c-interface and m-interface both depend on the core project:
compile project(':root:core')
c-interface and m-interface use the WAR plugin, but core does not and is just a jar.
In the core project, I am pulling in some file system dependencies with the following. One of these dependencies I cannot have packaged in the WARs generated by c-interface and m-interface. Previously I had this dependency in a nexus maven repository so I could exclude it by group,name,version in a providedRuntime configuration in c-interface and m-interface.
I cannot figure out how to do the same for the file dependency. The gradle dependencies task does not list file dependencies so I don't know what I would put in a providedRuntime.
I read http://issues.gradle.org/browse/GRADLE-471 but trying to use the idea there doesn't seem to remove the archive from my packages. Here is what I am currently defining (in core's build.gradle):
compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar')
compile(files('dependencies/compile/archive/management.jar')){ notPackaged = true } // Excludes it from all publications
Update
providedCompile without war plugin looked like a possibility. I set this up in the core build.gradle and it compiled fine, but c-interface and m-interface also needed the dependency at compile time. Including the file as providedCompile (or even a sanity check with compile) in c-interface and m-interface did not fix compile time errors related to missing the management.jar dependency. My speculation is because it was already scoped as providedCompile in core that the new declarations are ignored in c-interface and m-interface.
core/build.gradle:
configurations { providedCompile }
dependencies {
providedCompile files('dependencies/compile/archive/management.jar')
}
sourceSets.main.compileClasspath += configurations.providedCompile
sourceSets.test.compileClasspath += configurations.providedCompile
sourceSets.test.runtimeClasspath += configurations.providedCompile
c-interface/build.gradle:
providedCompile files('dependencies/compile/archive/management.jar')
There probably is a cleaner and simpler solution but you could then specify a custom configuration:
configurations {
compileOnly
}
and then specify all dependencies:
dependencies {
compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar')
compileOnly files('dependencies/compile/archive/management.jar')
}
Finally add the compileOnly configuration to classpaths of all source sets
sourceSets.all {
compileClasspath += configurations.compileOnly
}
This way management.jar should be on the classpath for compilation but won't be packaged.
EDIT
Only now I fully understand your problem. The following worked for me on a test project.
In core project gradle file:
repositories {
flatDir {
dirs 'dependencies/compile/archive'
}
}
dependencies {
compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar')
compile ':management:'
}
In project that depends on core:
repositories {
flatDir {
dirs new File(project(':core').projectDir, 'dependencies/compile/archive')
}
}
dependencies {
compile(project(':core')) {
exclude module: 'management'
}
compileOnly ':management':
}
sourceSets.all {
compileClasspath += configurations.compileOnly
}