Summary
I starting out to use apollo-android in my kotlin service since I want to consume other graphql endpoints
Version
v2.2.0
Description
I'm just trying out to consume the latest version of apollo android dependency and plugin. However, I'm running into error as such:
* What went wrong:
Execution failed for task ':bootJar'.
> Could not resolve all files for configuration ':productionRuntimeClasspath'.
> Could not resolve com.apollographql.apollo:apollo-api:2.2.0.
Required by:
project : > com.apollographql.apollo:apollo-runtime:2.2.0
project : > com.apollographql.apollo:apollo-runtime:2.2.0 > com.apollographql.apollo:apollo-normalized-cache:2.2.0
> Cannot choose between the following variants of com.apollographql.apollo:apollo-api:2.2.0:
- ios-api
- iosSim-api
- jvm-api
- jvm-runtime
- metadata-api
All of them match the consumer attributes:
- Variant 'ios-api' capability com.apollographql.apollo:apollo-api:2.2.0:
- Unmatched attributes:
- Found org.gradle.status 'release' but wasn't required.
...
I believe there is nothing strange in my build.gradle.kts :
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.3.0.RELEASE"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
kotlin("jvm") version "1.3.72"
kotlin("plugin.spring") version "1.3.72"
id("com.apollographql.apollo") version "2.2.0"
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
implementation("com.expediagroup:graphql-kotlin-spring-server:3.0.0-RC7")
implementation("com.apollographql.apollo:apollo-runtime:2.2.0")
}
apollo {
generateKotlinModels.set(true) // or false for Java models
}
Other info:
Any help would be much appreciated! Thank you 馃憤
Thanks for reaching out!
I'm guessing this has to do with Gradle attributes matching and _maybe_ the spring boot plugin doesn't declare requiring a JVM attribute? I'll try to reproduce with a sample spring boot project. In the meantime, you can try with Gradle 6.4+ that has better reporting for this class of errors. Also this Gradle issue has plenty of interesting information.
If you lookup the configuration that fails, you should be able to force resolving the JVM artifact with something like:
configurations.named("productionRuntimeClasspath").configure {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
}
}
I wonder if adding the jvm dependency explicitly would work? Notice the -jvm below. But I'm not even sure.
dependencies {
implementation("com.apollographql.apollo:apollo-runtime:2.2.0")
implementation("com.apollographql.apollo:apollo-api-jvm:2.2.0")
}
@martinbonnin: I've tried out forcing resolving the JVM artifact which allows the gradle clean build to succeed. However, since then I haven't been able to generate query from my .graphql file :(
@evantaurusta what error do you get when running ./gradlew generateApolloSources ?
@martinbonnin it works fine actually. It seems that the generated queries are located under build/generated/source/apollo/.... The "Get Started" section of the docs doesn't really mention the ./gradlew generateApolloSources it seems. Is it part of running a gradle clean build?
I also want to suggest expanding more on the doc for executing the generated queries. For example, the parameters for serverUrl() is kind of unclear for beginners.
As well as, an example for returning the response as a simple consumable object would be helpful.
The "Get Started" section of the docs doesn't really mention the ./gradlew generateApolloSources it seems. Is it part of running a gradle clean build?
It should be called automatically as a dependency of build indeed. Do not hesitate to file a bug if not the case.
I also want to suggest expanding more on the doc for executing the generated queries. For example, the parameters for serverUrl() is kind of unclear for beginners.
The documentation is a work in progress, thanks for the suggestions. If you're targeting Kotlin, you can also take a look at the tutorial that contains sample code and instructions for consuming models.
Most helpful comment
It should be called automatically as a dependency of
buildindeed. Do not hesitate to file a bug if not the case.The documentation is a work in progress, thanks for the suggestions. If you're targeting Kotlin, you can also take a look at the tutorial that contains sample code and instructions for consuming models.