The following lines are in a Gradle plugin:
project.configurations.compile.incoming.resolutionResult.allComponents.findAll { ..}
//...
Dependency dependency = project.dependencies.add('packaged', dependencyDescription)
Applying this plugin works in Gradle 2, but fails in Gradle 3 with:
Failed to apply plugin [id 'test']
A problem occurred configuring project ':my-project'.
Cannot change dependencies of configuration ':my-project:packaged' after it has been included in
dependency resolution.
Removing the 2nd line, the error disappears in Gradle 3.
Now I would like to know the time & place which is valid in Gradle 3 to update the configuration. Reading the Gradle 3 manual i could not find an answer.
It looks like incoming.resolutionResult from the line
project.configurations.compile.incoming.resolutionResult.allComponents.findAll {..}
is triggering dependency resolution so any modification to the dependencies after that causes the error.
The resolution can be eliminated by doing a copy and reading from it instead.
project.configurations.compile.copyRecursive().incoming.resolutionResult.allComponents.findAll {..}
Related
My application is dependent upon the following artifact
com.oracle.jdbc:ojdbc8
which has a circular dependency with
com.oracle.jdbc:ucp
The build fails with the following error
ERROR: /private/var/tmp/_bazel_me/4f1994ece960b360388a372b5e6aa4b2/external/maven/BUILD:2757:11: in jvm_import rule #maven//:com_oracle_jdbc_ojdbc8: cycle in dependency graph:
//package/java:MyClass
.-> #maven//:com_oracle_jdbc_ojdbc8
| #maven//:com_oracle_jdbc_ucp
`-- #maven//:com_oracle_jdbc_ojdbc8
Is there a way to get around this?
Looking at the artifact here:
https://mvnrepository.com/artifact/com.oracle.jdbc/ojdbc8
there's only one version:
https://mvnrepository.com/artifact/com.oracle.jdbc/ojdbc8/12.2.0.1
and it depends on com.oracle.jdbc:upc, which indeed depends back on com.oracle.jdbc:ojdbc8:12.2.0.1
https://mvnrepository.com/artifact/com.oracle.jdbc/ucp/12.2.0.1
This was surely a mistake, because I don't believe that maven allows circular dependencies either.
Looking back at https://mvnrepository.com/artifact/com.oracle.jdbc/ojdbc8, it says this was moved to https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8, and the version of upc there has no dependencies:
https://mvnrepository.com/artifact/com.oracle.database.jdbc/ucp/12.2.0.1
So maybe com.oracle.database.jdbc:ojdbc8 will work for you (or the specific version com.oracle.database.jdbc:ojdbc8:12.2.0.1, since the previous one was 12.2.0.1 and the latest version is 21.4.0.0.1)
Interestingly, com.oracle.database.jdbc:ojdbc8 says it was also moved: https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8
I have the problem after adding module in gradle file.
Earlier I have following structure of my project
---app (main module)
---customview (dependency module add as `compile project` into the main module gradle file)
---daogenerator (separate module)
Daogenerator module was used as separate module to generate dao classes and model classes by Greendao library.
Everything was fine, but one problem that I should duplicate some common lets say Contract classes in both modules, so I decided to optimize and have only one file.
And as far as I cannot use classes from different modules if there are not specified in the gradle file as dependency.
So I added this line into my gradle file in the app module
compile project(':daogenerator')
After that I successfully imported common class but failed to compile the project. I got
finished with non-zero exit value 1 .....
Nothing more about the problem.
What I have already tried to do
Clean/Rebuild
Add dexOptions {
javaMaxHeapSize "4g"
jumboMode true
incremental true
} to the main app gradle file
Invalidate & Restart
Run ./gradlew assembleDebug --info got
Successfully started process 'command
'/usr/lib/jvm/java-8-oracle/bin/java'' PREDEX CACHE HITS: 0 PREDEX
CACHE MISSES: 1 Stopped 0 compiler daemon(s). Could not read standard
output of: command '/usr/lib/jvm/java-8-oracle/bin/java'.
java.io.IOException: Stream closed
at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:170)
I have no idea what is wrong.
Sorry, this was my fault. I have forgotten that GreenDao library is simple java application it has entry point public static void main(String[] args) throws Exception
So it doesn't make any sense to compile it together with android application
Disclaimer:
I'm new to Gradle, have read a lot of docs, and I don't know whether my maven-style understanding is tripping me out, or whether it's the sleep dep (kids - don't ask), but I'm still not getting it.
Problem Background:
I have a project that consists of several modules.
One of the modules, let's call it data-structure defines a data structure
Another module, data-structure-fabsearch, defines an implementation for a data source for the data structure, and finally
A third module, fabsearch-common, defines some common data source classes (eg: connection management to a fabsearch data source etc).
The reason I've done it like this is because there's actually another module that also uses the fabsearch-common stuff.
Anyway, my data-structure-fabsearch build.gradle looks something like this:
dependencies {
compile project(:data-structure)
compile project(:fabsearch-common)
}
The fabsearch-common module declares depedencies for the fabsearch api (let's call it fabsearch-api-1.0.0).
So, the dependency tree for data-structure-fabsearch should look like this:
- data-structure-fabsearch
- data-structure
- fabsearch-common
- fabsearch-api-1.0.0
This was all working wonderfully last night. This morning I came to work and all of a sudden those dependencies don't resolve anymore. References to fabsearch-api-1.0.0 classes are no longer found.
What I've Tried
1. In the parent build.gradle:
project(':data-structure-fabsearch'){
apply plugin: 'java'
dependencies {
compile project(path: ':data-structure', configuration: 'compile')
compile project(path: ':fabsearch-common', configuration: 'compile')
}
}
I've tried this with and without the configuration setting.
2. In the data-structure-fabsearch build.gradle file, adding the configuration parameter.
3. Restarting IntelliJ
4. Clicking the refresh icon in the Gradle tool window (repeatedly)
5. Reading all about transitive dependencies in the Gradle user guides
6. Drinking tea (repeatedly)
None of the above work.
What I'm Expecting
I'm expecting that the fabsearch-common dependencies (the fabsearch-api jars) should also be included in the data-structure-fabsearch dependency tree. All references to fabsearch-api classes in data-structure-fabsearch should resolve etc etc.
My Question[s]
Whilst this is possible in Maven, is it possible in Gradle?
What do I have to do to get it to work?
How much sleep dep can you take without dying?
Many thanks for any help.
Turns out the problem wasn't gradle at all. The problem was IntelliJ.
It got it's knickers into a proper twist!
Solution:
1. Close the project in IntelliJ
2. Delete the .idea directory
3. Delete all .iml files and any other IntelliJ cra-useful files
4. Open project in IntelliJ, choose same directory. Problem disappears.
I'm rather baffled on this. If I pass in this version number, gradle fails:
gradle -Pversion=120151021 build
:eventing:compileJava
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':eventing:compile'.
> Could not find eventing-test.jar
I've no idea why it thinks it needs to find eventing-test.jar. That's the name I have it creating for the jar of test classes. Seems like a red herring of a message.
If I simply put ANY alpha character in front of the version string, it works:
gradle -Pversion=z120151021 build
:eventing:compileJava
:eventing:processResources UP-TO-DATE
:eventing:classes
etc
etc
It seems to be a problem if it just starts with numbers:
gradle -Pversion=11abc build
:eventing:compileJava
FAILURE: Build failed with an exception.
Though, in a truly bizarre turn, it's ok if it starts with a single "1":
gradle -Pversion=1abc build
I don't see anything in the Gradle documentation that says a numeric version number is a problem.
I still don't know why the original setup didn't work, but I worked around it as follows. Inside each jar and publish target, I specifically pulled in another variable as the version. For example.
task testJar(type: Jar) {
from sourceSets.test.output
version = System.getProperty('RELEASE_VERSION', "unversioned")
appendix="test"
}
jar {
version = System.getProperty('RELEASE_VERSION', "unversioned")
}
Note, it does NOT work to do this trick to set version at the outer gradle level. It results in the same error I had before.
Does not work:
apply plugin: 'application'
version = System.getProperty('RELEASE_VERSION', "unversioned")
...define tasks and such that would use "version" ...
Does anyone know how to run the tests from a different gradle project and still get emma coverage reporting data?
Here is my current layout:
Root/
settings.gradle (no explicit build.gradle - just defines all subprojects)
SubProjectA/
build.gradle
src/ (all real source is here)
SubProjectATest/
build.gradle
src/ (all testing code is here)
SubProjectB/ (similar structure as A)
SubProjectBTest/ (similar structure as ATest)
I am currently using the emma plugin, and I would like to build SubProjectA and run all the tests in SubProjectATest from within the build.gradle of SubProjectA.
Here are some things I tried inside the build.gradle of SubProjectA
testCompile project(':SubProjectATest').sourceSets.test.classes (as suggested by this article), but I got an error "Could not find property 'sourceSets' on project"
Just the straight-up testCompile project(':SubProjectATest'), but then I get "..SubProjectA/build/classes/test', not found" and also "Skipping task ':SubProjectA:compileTestJava' as it has no source files."
Simply adding a sourceSet like the following:
test {
java {
srcDir '../SubProjectATest/src'
}
}
Adding the source set in (option 3) is the only option that worked, but it seems sloppy to do it this way. Does anyone know how to do this using project dependencies?
Update #1
I also tried one of the answers below to use test.dependsOn and the tests do run, but the emma plugin reported the following: build/classes/test', not found
1. and 2. just add classes to the test compile class path. This doesn't have any effect on which tests are going to be executed.
3. is the wrong approach because you should not add sources from project X to project Y.
If what you want is that gradle :SubProjectA:test also executes :SubProjectATest:test, all you need to do is to add a task dependency:
SubProjectA/build.gradle:
test.dependsOn(":subProjectATest:test")
By the way, what is your motivation for putting the tests in a separate project?