I have a Multi Project wich has the following structure:
core
pluginApi
plugins/globalOptions
plugins/commandPlugin
Where "plugins" is just a directory.
Now I have a couple classes inside "globalOptions":
at.lyze.plugin.globalOptions.extensionpoint.OptionExtension
at.lyze.plugin.globalOptions.extensionpoint.OptionHandlerExtension
And one class inside "commandPlugin":
at.lyze.plugin.commandPlugin.CommandPluginTest
The "CommandPluginTest" class uses"OptionExtension" and "OptionHandlerExtension" from the other project:
import at.lyze.plugin.globalOptions.extensionpoint.OptionExtension;
import at.lyze.plugin.globalOptions.extensionpoint.OptionHandlerExtension;
List<OptionHandlerExtension> optionHandlers = wrapper.getPluginManager().getExtensions(OptionHandlerExtension.class);
for (OptionHandlerExtension optionHandler : optionHandlers) {
logger.warn(optionHandler.getOption(getClass(), "TestOption"));
}
My gradle build files look like:
"globalOptions":
dependencies {
compile project(':pluginApi')
}
"commandPlugin":
dependencies {
compile project(':plugins/globalOptions')
compile project(':pluginApi')
}
When trying to run the "jar" task on every project I get the following error:
Note: Extension found in at.lyze.plugin.globalOptions.GlobalOptions$TestExtension
:plugins/globalOptions:compileJava
:plugins/globalOptions:processResources UP-TO-DATE
:plugins/globalOptions:classes
:plugins/globalOptions:jar
Note: Extension found in at.lyze.plugin.commandPlugin.CommandPluginTest$BlarghExtension
C:\Users\wml\Desktop\LocalRepos\darkowlbot\plugins\commandPlugin\src\main\java\at\lyze\plugin\commandPlugin\Co mmandPluginTest.java:3: error: package at.lyze.plugin.globalOptions.extensionpoint does not exist
import at.lyze.plugin.globalOptions.extensionpoint.OptionExtension;
^
C:\Users\wml\Desktop\LocalRepos\darkowlbot\plugins\commandPlugin\src\main\java\at\lyze\plugin\commandPlugin\Co mmandPluginTest.java:4: error: package at.lyze.plugin.globalOptions.extensionpoint does not exist
import at.lyze.plugin.globalOptions.extensionpoint.OptionHandlerExtension;
^
C:\Users\wml\Desktop\LocalRepos\darkowlbot\plugins\commandPlugin\src\main\java\at\lyze\plugin\commandPlugin\Co mmandPluginTest.java:52: error: cannot find symbol
public static class BlarghExtension implements EventProcessorExtension, OptionExtension {
^
symbol: class OptionExtension
location: class CommandPluginTest
C:\Users\wml\Desktop\LocalRepos\darkowlbot\plugins\commandPlugin\src\main\java\at\lyze\plugin\commandPlugin\CommandPluginTest.java:76: error: cannot find symbol
public void initializeOptions(OptionHandlerExtension optionHandlerExtension) {
^
symbol: class OptionHandlerExtension
location: class CommandPluginExtensionClass
4 errors
:plugins/commandPlugin:compileJava FAILED
FAILURE: Build failed with an exception.
Have I done something wrong here or why does this fail?
I can provide additional information if needed.
Running gradle 2.9
Edit:
Settings.gradle (Global project with every include)
rootProject.name = 'DarkOwlBot'
include 'pluginApi'
include 'core'
include 'plugins/globalOptions'
include 'plugins/commandPlugin'
include 'plugins/guiFeederService'
Most likely, gradle has problems with the '/' in project names. By default the project name is also used to create the jar for the project. This likely results in wrong file paths.
I think your best options to solve this are:
Change the include statements in your settings.gradle file to be
include ':plugins:globalOptions' and reference globalOptions by
compile project(':plugins:globalOptions')
Change the include statement in your settings.gradle file to be
include ':globalOptions' and configure the project directory explicit via project(':globalOptions').projectDir = file('plugins/globalOptions')
and reference it in your dependency block via compile project(':globalOptions')
In addition to what #ReneGroeschke said, you should leave out the into ('classes') line here. You're altering the structure of the produced artifact.
Related
How can I add an Android build dependency to my custom capacitor plugin for app rate based on
https://developer.android.com/guide/playcore/in-app-review/kotlin-java#java
It fails the build with not finding com.google.android.play.core so I wonder how can I add it as a dependency to the component build?
Below is the error
/AppRate.java:9: error: package com.google.android.play.core.review does not exist
import com.google.android.play.core.review.ReviewInfo;
^
/AppRate.java:10: error: package com.google.android.play.core.review does not exist
import com.google.android.play.core.review.ReviewManager;
^
/AppRate.java:11: error: package com.google.android.play.core.review does not exist
import com.google.android.play.core.review.ReviewManagerFactory;
^
/AppRate.java:12: error: package com.google.android.play.core.tasks does not exist
import com.google.android.play.core.tasks.Task;
^
/AppRate.java:17: error: class AppRate clashes with package of same name
public class AppRate extends Plugin {
^
/AppRate/BuildConfig.java:4: error: package me.url.AppRate clashes with class of same name
package me.url.AppRate;
^
/AppRate.java:21: error: cannot find symbol
Activity activity = this.cordova.getActivity();
I am also not sure about the clash error, but that is a separate topic I guess.
Note - I tried integrating the ionic native plugins but had weird build issues. iOS now works with my custom plugin, fixing Android now.
Try these steps to see:
Delete the Buildconfig.java
Refactor -> Rename, error class.
Build -> Rebuild Project!
--
And if not, share what you have in the file: build.gradle in the defaultConfig section and AndroidManifest from the manifest section.
I had to add
implementation "com.google.android.play:core:1.10.2"
to my build.grade file.
The project has a gradle module to build JAX2B classes.
The XJC configuration already uses annotations:
bindingFiles = project.files("$projectDir/src/main/resources/binding.xjb",
"$projectDir/src/main/resources/annotations.xjb")
// Needed to execute custom annotations
options.add("-Xannotate")
}
I thought I could add options to get equals() and hashCode()
xjc {
bindingFiles = project.files("$projectDir/src/main/resources/binding.xjb",
"$projectDir/src/main/resources/annotations.xjb")
options.addAll("-Xannotate", "-Xequals", "-XhashCode")
}
The methods are not on the class and there are no errors or warnings in the build log.
How do I generate those methods?
PS: Here are the build file dependencies
dependencies {
implementation(project(":xxx:xxx-api"))
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.2")
xjcPlugins("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.2")
xjcPlugins("org.jvnet.jaxb2_commons:jaxb2-basics-annotate:1.1.0")
}
UPDATED
Thanks to #thokuest for spotting a missing dependency.
The project has a gradle module to build JAX2B classes, but I'm getting build errors adding the "-Xequals" option:
build/generated/sources/xjc/java/org/pen/ProductOutputType.java:16: error: package org.jvnet.jaxb2_commons.locator.util does not exist
import org.jvnet.jaxb2_commons.locator.util.LocatorUtils;
^
build/generated/sources/xjc/java/org/pen/ProductOutputType.java:47: error: cannot find symbol
public class ProductOutputType implements Equals2
^
I've created a minimum example as a gist -- build.gradle.kts
equals() and hashCode() are contributed by the jaxb2-basics plugin.
xjcPlugins 'org.jvnet.jaxb2_commons:jaxb2-basics:1.11.1'
According to the project's wiki, there's a runtime dependency to org.jvnet.jaxb2_commons:jaxb2-basics-runtime:1.11.1 that you would need to add as well.
Update
Dependency org.jvnet.jaxb2_commons:jaxb2-basics-runtime:1.11.1 must be in scope implementation as otherwise a build error as described in the question occurs.
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)
Running into problems extracting tasks from a build.gradle file to then be applied, back into the app/root build.gradle file. The compiler can resolve MarkupBuilder and JsonSlurper fine but cannot resolve the following: import org.apache.commons.lang.StringEscapeUtils.
I've tried adding it as a dependency within the newly created script and also within the app and project levels.
'org.apache.commons.lang:commons-lang:3.5'
The error is below
Could not compile script '/project/app/newscript.gradle'.
startup failed:
> script '/project/app/newscript.gradle': 18: unable to resolve class org.apache.commons.lang.StringEscapeUtils
# line 18, column 1.
import org.apache.commons.lang.StringEscapeUtils
^
1 error
Am I doing something wrong or is this not possible? Would I need to include the script in a different way than apply script: newscript.gradle or another plugin within the newscript.gradle?
A Gradle script is basically a Groovy file. Which in turn gets compiled into JVM bytecode, similar to Java classes. So when compiling a script with an import, the imported classes must be on the classpath. Some classes like the MarkupBuilder are available by default (included either by Groovy or Gradle).
You have to add something like this to be able to use the classes in your script:
import org.apache.commons.lang.StringEscapeUtils;
buildscript {
repositories {
mavenCentral();
}
dependencies {
classpath 'org.apache.commons.lang:commons-lang:3.5'
}
}
The buildscript closure will add the library on the classpath of the Gradle script and you should be able to use its classes.
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?