Could not find io.confluent:kafka-protobuf-serializer:6.0.0 - maven

The straight question is: why is Gradle not resolving this dependency I added
dependencies {
//kafka-protobuf-serializer
implementation("io.confluent:kafka-protobuf-serializer:6.0.0")
}
?
Accoring to mvn this is how I add such dependency in my build.gradle
compile group: 'io.confluent', name: 'kafka-protobuf-serializer', version: '6.0.0'
All my other dependencies are added with "implementation ...". So far so good. But for this speficic I got
Execution failed for task ':extractIncludeProto'.
> Could not resolve all files for configuration ':compileProtoPath'.
> Could not find io.confluent:kafka-protobuf-serializer:6.0.0.
Searched in the following locations:
- file:/C:/Users/Cast/.m2/repository/io/confluent/kafka-protobuf-serializer/6.0.0/kafka-protobuf-serializer-6.0.0.pom
- https://jcenter.bintray.com/io/confluent/kafka-protobuf-serializer/6.0.0/kafka-protobuf-serializer-6.0.0.pom
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
What I am missing or messing here?
Here is the whole build.gradle
plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.72"
id "org.jetbrains.kotlin.kapt" version "1.3.72"
id "org.jetbrains.kotlin.plugin.allopen" version "1.3.72"
id "application"
id 'com.google.protobuf' version '0.8.13'
}
version "0.2"
group "account-control"
repositories {
mavenLocal()
jcenter()
}
configurations {
// for dependencies that are needed for development only
developmentOnly
}
dependencies {
kapt(enforcedPlatform("io.micronaut:micronaut-bom:$micronautVersion"))
kapt("io.micronaut:micronaut-inject-java")
kapt("io.micronaut:micronaut-validation")
implementation(enforcedPlatform("io.micronaut:micronaut-bom:$micronautVersion"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
implementation("io.micronaut:micronaut-runtime")
// implementation("io.micronaut.grpc:micronaut-grpc-runtime")
implementation("io.micronaut.grpc:micronaut-grpc-server-runtime:$micronautGrpcVersion")
implementation("io.micronaut.grpc:micronaut-grpc-client-runtime:$micronautGrpcVersion")
implementation("io.grpc:grpc-kotlin-stub:${grpcKotlinVersion}")
//Kafka
implementation("io.micronaut.kafka:micronaut-kafka")
//vertx
implementation("io.micronaut.sql:micronaut-vertx-mysql-client")
//implementation("io.micronaut.configuration:micronaut-vertx-mysql-client")
compile 'io.vertx:vertx-lang-kotlin:3.9.4'
//mongodb
implementation("org.mongodb:mongodb-driver-reactivestreams:4.1.1")
//kafka-protobuf-serializer
implementation("io.confluent:kafka-protobuf-serializer:6.0.0")
runtimeOnly("ch.qos.logback:logback-classic:1.2.3")
runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin:2.9.8")
kaptTest("io.micronaut:micronaut-inject-java")
testImplementation enforcedPlatform("io.micronaut:micronaut-bom:$micronautVersion")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.3.0")
testImplementation("io.micronaut.test:micronaut-test-junit5")
testImplementation("org.mockito:mockito-junit-jupiter:2.22.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.3.0")
testRuntime("org.jetbrains.spek:spek-junit-platform-engine:1.1.5")
}
test.classpath += configurations.developmentOnly
mainClassName = "account-control.Application"
test {
useJUnitPlatform()
}
allOpen {
annotation("io.micronaut.aop.Around")
}
compileKotlin {
kotlinOptions {
jvmTarget = '11'
//Will retain parameter names for Java reflection
javaParameters = true
}
}
//compileKotlin.dependsOn(generateProto)
compileTestKotlin {
kotlinOptions {
jvmTarget = '11'
javaParameters = true
}
}
tasks.withType(JavaExec) {
classpath += configurations.developmentOnly
jvmArgs('-XX:TieredStopAtLevel=1', '-Dcom.sun.management.jmxremote')
}
sourceSets {
main {
java {
srcDirs 'build/generated/source/proto/main/grpc'
srcDirs 'build/generated/source/proto/main/grpckt'
srcDirs 'build/generated/source/proto/main/java'
}
}
}
protobuf {
protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" }
plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" }
grpckt { artifact = "io.grpc:protoc-gen-grpc-kotlin:${grpcKotlinVersion}" }
}
generateProtoTasks {
all()*.plugins {
grpc {}
grpckt {}
}
}
}
*** first edition
Execution failed for task ':extractIncludeProto'.
> Could not resolve all files for configuration ':compileProtoPath'.
> Could not resolve com.squareup.wire:wire-schema:3.2.2.
Required by:
project : > io.confluent:kafka-protobuf-serializer:6.0.0 > io.confluent:kafka-protobuf-provider:6.0.0
> The consumer was configured to find a component, preferably only the resources files. However we cannot choose between the following variants of com.squareup.wire:wire-schema:3.2.2:
- jvm-api
- jvm-runtime
- metadata-api
All of them match the consumer attributes:
- Variant 'jvm-api' capability com.squareup.wire:wire-schema:3.2.2 declares a component, packaged as a jar:
- Unmatched attributes:
- Provides release status but the consumer didn't ask for it
- Provides an API but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but the consumer didn't ask for it
- Variant 'jvm-runtime' capability com.squareup.wire:wire-schema:3.2.2 declares a component, packaged as a jar:
- Unmatched attributes:
- Provides release status but the consumer didn't ask for it
- Provides a runtime but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but the consumer didn't ask for it
- Variant 'metadata-api' capability com.squareup.wire:wire-schema:3.2.2:
- Unmatched attributes:
- Doesn't say anything about its elements (required them preferably only the resources files)
- Provides release status but the consumer didn't ask for it
- Provides a usage of 'kotlin-api' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'common' but the consumer didn't ask for it
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':extractIncludeProto'.
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:38)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
at
...
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve com.squareup.wire:wire-schema:3.2.2.
Required by:
project : > io.confluent:kafka-protobuf-serializer:6.0.0 > io.confluent:kafka-protobuf-provider:6.0.0
Caused by: org.gradle.internal.component.AmbiguousConfigurationSelectionException: The consumer was configured to find a component, preferably only the resources files. However we cannot choose between the following variants of com.squareup.wire:wire-schema:3.2.2:
- jvm-api
- jvm-runtime
- metadata-api
All of them match the consumer attributes:
- Variant 'jvm-api' capability com.squareup.wire:wire-schema:3.2.2 declares a component, packaged as a jar:
- Unmatched attributes:
- Provides release status but the consumer didn't ask for it
- Provides an API but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but the consumer didn't ask for it
- Variant 'jvm-runtime' capability com.squareup.wire:wire-schema:3.2.2 declares a component, packaged as a jar:
- Unmatched attributes:
- Provides release status but the consumer didn't ask for it
- Provides a runtime but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but the consumer didn't ask for it
- Variant 'metadata-api' capability com.squareup.wire:wire-schema:3.2.2:
- Unmatched attributes:
- Doesn't say anything about its elements (required them preferably only the resources files)
- Provides release status but the consumer didn't ask for it
- Provides a usage of 'kotlin-api' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'common' but the consumer didn't ask for it
at org.gradle.internal.component.model.AttributeConfigurationSelector.selectConfigurationUsingAttributeMatching(AttributeConfigurationSelector.java:105)
at org.gradle.internal.component.model.AttributeConfigurationSelector.selectConfigurationUsingAttributeMatching(AttributeConfigurationSelector.java:108)
at org.gradle.internal.component.model.AttributeConfigurationSelector.selectConfigurationUsingAttributeMatching(AttributeConfigurationSelector.java:51)
at org.gradle.internal.component.external.model.ConfigurationBoundExternalDependencyMetadata.selectConfigurations(ConfigurationBoundExternalDependencyMetadata.java:98)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.EdgeState.calculateTargetConfigurations(EdgeState.java:253)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.EdgeState.attachToTargetConfigurations(EdgeState.java:153)
at ...org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)

When using mvnrepository.com, take note of which repository the module is available in as you only have JCenter configured for your build (which is usually fine, just not in this case). Here the dependency is in the Confluent repository:
So you will need to add this repository to your build:
repositories {
mavenLocal()
jcenter()
maven { url "https://packages.confluent.io/maven/" }
}

Related

How to ignore projects from Gradle dependency transformation

I'm following the sample code in Gradle's Transform dependency artifacts on resolution page.
def artifactType = Attribute.of('artifactType', String)
def minified = Attribute.of('minified', Boolean)
dependencies {
attributesSchema {
attribute(minified)
}
artifactTypes.getByName("jar") {
attributes.attribute(minified, false)
}
}
configurations.all {
afterEvaluate {
if (canBeResolved) {
attributes.attribute(minified, true)
}
}
}
dependencies {
registerTransform(Minify) {
from.attribute(minified, false).attribute(artifactType, "jar")
to.attribute(minified, true).attribute(artifactType, "jar")
}
}
dependencies {
implementation('com.google.guava:guava:27.1-jre')
implementation(project(':my-sub-project'))
}
When I run gradlew :my-app:test I get:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':my-app:test'.
> Could not resolve all task dependencies for configuration ':my-app:testRuntimeClasspath'.
> Could not resolve project :my-sub-project.
Required by:
project :my-app
> The consumer was configured to find a runtime of a library compatible with Java 17,
packaged as a jar, preferably optimized for standard JVMs, and its dependencies
declared externally, as well as attribute 'minimized' with value 'true'.
However we cannot choose between the following variants of project :my-sub-project:
- archives
- checkstyle
- default
- jacocoAgent
- jacocoAnt
- runtimeElements
All of them match the consumer attributes:
...
- Variant 'runtimeElements' capability my_project:my-sub-project:unspecified declares a runtime of a library compatible with Java 17, packaged as a jar, and its dependencies declared externally:
- Unmatched attributes:
- Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
- Doesn't say anything about minimized (required 'true')
How can I exclude our internal projects (and maybe even libraries within our group) from the requirement of being minimized?
I've managed to fix the problem with allprojects:
configurations.all {
// Skip internal projects
allprojects {
attributes.attribute(minimized, true)
}
// Request minimized=true on all resolvable configurations
afterEvaluate {
if (canBeResolved) {
attributes.attribute(minimized, true)
}
}
}

Gluon Mobile - Too many classes in --main-dex-list, main dex capacity exceeded

I'm using GluonHQ's JavaFX to create mobile applications for Android. I'm using OpenJDK 8 and OpenJFX 8.
asus#asus-pc:~/Dokument/Eclipse-Workspace/Deeplearning2C$ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~19.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
asus#asus-pc:~/Dokument/Eclipse-Workspace/Deeplearning2C$
When I generate a android application, I write this command.
asus#asus-pc:~/Dokument/Eclipse-Workspace/Deeplearning2C$ ./gradlew android
But I get this error. I don't understand what it is and I have never got that before.
> Task :Deeplearning2CApp:dex FAILED
[ant:java] Java Result: 2
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':Deeplearning2CApp:dex'.
> UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:548)
at com.android.dx.command.dexer.Main.runMultiDex(Main.java:368)
at com.android.dx.command.dexer.Main.runDx(Main.java:289)
at com.android.dx.command.dexer.Main.main(Main.java:247)
at com.android.dx.command.Main.main(Main.java:94)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 6m 57s
11 actionable tasks: 9 executed, 2 up-to-date
asus#asus-pc:~/Dokument/Eclipse-Workspace/Deeplearning2C$
According to this question, the suggestions in the answer was was:
(The easiest solution, but not suitable for most of the applications) Change your minSdkVersion to 21.
Shrink your application code. This was discussed many times previously (see here and here).
If none of the above solutions work for you, you can try to use my workaround for this issue - I'm patching the Android gradle plugin to not include Activity classes in main dex. It's a bit hacky, but works well for me.
Too many classes in --main-dex-list, main dex capacity exceeded
My project is very minimal and I don't use many dependencies at all. So I cannot shrink down my code. That's is impossible for me. I cannot change the SDK version because I'm running at the lowest Java 8 version. The last suggestion I don't want to try because I don't like "quick hacks" for projects.
Do you think it has something with Deeplearning4J dependency?
My gradle.build file looks like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.17'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'se.danielmartensson.Main'
dependencies {
compile 'com.gluonhq:charm:5.0.2'
compile group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '1.0.0-beta4'
compile group: 'org.nd4j', name: 'nd4j-native-platform', version: '1.0.0-beta4'
compile group: 'org.datavec', name: 'datavec-api', version: '1.0.0-beta4'
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
}
jfxmobile {
downConfig {
version = '3.8.6'
// Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'se.danielmartensson.**.*',
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}
My project can be downloaded from here:
https://github.com/DanielMartensson/Deeplearning2C
Edit:
I tried to compile gradle.build file with dexOptions . Se below and the error too.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.17'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'se.danielmartensson.Main'
dependencies {
compile 'com.gluonhq:charm:5.0.2'
compile group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '1.0.0-beta4'
compile group: 'org.nd4j', name: 'nd4j-native-platform', version: '1.0.0-beta4'
compile group: 'org.datavec', name: 'datavec-api', version: '1.0.0-beta4'
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
}
jfxmobile {
downConfig {
version = '3.8.6'
// Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
dexOptions {
additionalParameters = ['--minimal-main-dex']
keepRuntimeAnnotatedClasses = false
javaMaxHeapSize = '4g'
}
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'se.danielmartensson.**.*',
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}
Error output:
> Task :Deeplearning2CApp:dex
[ant:java] Java Result: 1
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':Deeplearning2CApp:dex'.
> warning: Ignoring InnerClasses attribute for an anonymous inner class
(EDU.oswego.cs.dl.util.concurrent.FutureResult$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
..
...
.....
......
.......
warning: Ignoring InnerClasses attribute for an anonymous inner class
(EDU.oswego.cs.dl.util.concurrent.misc.TestLoop$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000701100000, 401080320, 0) failed; error='Cannot allocate memory' (errno=12)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 6m 52s
11 actionable tasks: 9 executed, 2 up-to-date
asus#asus-pc:~/Dokument/Eclipse-Workspace/Deeplearning2C$

Plugin [id: 'com.github.ben-manes.versions'] was not found in any of the following sources

Here is my gradle build file and getting the following error:-
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java Library project to get you started.
* For more details take a look at the Java Libraries chapter in the Gradle
* user guide available at https://docs.gradle.org/4.10.2/userguide/java_library_plugin.html
*/
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'de.fuerstenau.buildconfig' version '1.1.8' apply true
id 'eclipse'
id 'com.github.ben-manes.versions' version '$version'
id 'com.palantir.git-version'
}
dependencies {
classpath(
"gradle.plugin.com.palantir.gradle.gitversion:gradle-git-version:0.5.3",
"com.github.ben-manes:gradle-versions-plugin:0.13.0",
"gradle.plugin.de.fuerstenau:BuildConfigPlugin:1.1.4",
"net.ltgt.gradle:gradle-apt-plugin:0.13",
"com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3",
)
compile(
"com.squareup.okhttp3:okhttp:$versions.okhttp",
"com.google.code.gson:gson:$versions.gson",
)
compileOnly(
"com.google.auto.value:auto-value:$versions.autoValue",
deps.nullityAnnotations,
"com.github.kevinmost.auto-value-custom-hashcode-equals:adapter:$versions.customHashCodeEquals",
)
apt(
"com.google.auto.value:auto-value:$versions.autoValue",
"com.gabrielittner.auto.value:auto-value-with:1.0.0",
"com.github.kevinmost.auto-value-custom-hashcode-equals:processor:$versions.customHashCodeEquals",
)
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:23.0'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
mavenLocal()
mavenCentral()
maven { url "https://jitpack.io" }
}
buildConfig {
packageName = "api2"
clsName = "BuildConfig"
}
ext.versions = [
okhttp: "3.4.1",
gson: "2.7",
autoValue: "1.5.2",
slf4j: "1.7.21",
kotlin: "1.0.5-2",
customHashCodeEquals: "db3442d",
]
Error:_
* What went wrong:
Plugin [id: 'com.github.ben-manes.versions'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)
The plugins DSL has some limitations described here Plugins DSL - Constraine syntax: you cannot use variables to set the version.
The form is:
plugins {
id «plugin id» version «plugin version» [apply «false»]
}
Where «plugin id» and «plugin version» must be constant, literal, strings
You should apply this plugin as follows:
plugins {
id "com.github.ben-manes.versions" version "0.20.0"
}

Custom Metadata in Gradle dependency descriptor

This is how i have added dependencies in my build.gradle
// Dependency Versioning
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Edgware.RELEASE'
mavenBom 'io.pivotal.spring.cloud:spring-cloud-services-dependencies:1.5.0.RELEASE'
mavenBom 'org.springframework.boot:spring-boot-dependencies:1.5.15.RELEASE'
}
dependencies {
dependency 'io.springfox:springfox-swagger2:2.8.0'
dependency 'io.springfox:springfox-swagger-ui:2.8.0'
dependency 'org.flywaydb:flyway-core:4.2.0'
dependency 'com.microsoft.sqlserver:mssql-jdbc:6.2.2.jre8'
}
}
I am looking to add a custom-number with each dependency. This number is our Approval number provided by our Architecture team for approval of using that dependency within our enterprise..
Say if my Architecture team has Approved to use io.springfox:springfox-swagger2:2.8.0 dependency and if the approval number is APPL-1054 then i have to add this number also as a metadata along within the dependency tag with which i will have a different gradle task to consume those numbers
something that looks like dependency 'io.springfox:springfox-swagger2:2.8.0' : APPL-1054
Please help with your ideas
You could set the approvals in a Map then use dependency resolution to validate the approvals. The map could come from some web source as long as you can get it to a map somehow. Here is a simple example
buildscript {
repositories {
jcenter()
}
dependencies {
gradleApi()
}
}
group 'com.stackoverflow'
version '1.0-SNAPSHOT'
repositories {
jcenter()
}
configurations {
audited.extendsFrom(compile)
}
Map<String, Object> approvedDeps = [
'junit:junit:4.12': 'APPROVAL-1234'
]
dependencies {
compile gradleApi()
audited 'junit:junit:4.12'
audited 'org.mockito:mockito-android:2.22.0'
}
dependencies {
components {
all { ComponentMetadataDetails details ->
String requestedArtifact = "${details.id.group}:${details.id.name}:${details.id.version}"
String approvalCode = approvedDeps[requestedArtifact]
if (approvalCode == null) {
throw new GradleException("Use of unapproved dependency (${requestedArtifact})")
}
logger.lifecycle("Requested dependency (${requestedArtifact}) is approved: ${approvalCode}")
return details
}
}
}
// lets fake some action that would trigger dependency resolution
configurations.eachWithIndex { Configuration entry, int index ->
if (entry.canBeResolved) {
entry.resolve()
print("Resolved index: ${index}")
}
}
Now if we run ./gradlew clean build we get an error as an unapproved dependency was added.
$ ./gradlew clean build
> Configure project :
Requested dependency (junit:junit:4.12) is approved: APPROVAL-1234
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/jonstanford/dev/stackoverflow/q52427676/build.gradle' line: 36
* What went wrong:
A problem occurred evaluating root project 'q52427676'.
> Could not resolve all dependencies for configuration ':audited'.
> There was an error while evaluating a component metadata rule for org.mockito:mockito-android:2.22.0.
> Use of unapproved dependency (org.mockito:mockito-android:2.22.0)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
Of course you could move this functionality to a custom plugin or such but I think the base idea holds.

Issue getting Gradle apt plugin to work with QueryDSL, lombok & mapstruct

I am trying to get gradle apt plugin to work with:
QueryDSL
Mapstruct
Lombok
Here is what I have attempted:
plugins {
id 'net.ltgt.apt' version '0.10'
}
description = "Bignibou Common"
apply plugin: 'org.springframework.boot'
dependencyManagement {
dependencies {
dependency "org.elasticsearch:elasticsearch:${elasticsearchVersion}"
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa") {
exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
}
compile("org.springframework.boot:spring-boot-starter-mail")
compile('org.springframework.security:spring-security-core')
compile('org.hibernate:hibernate-validator')
compile("org.hibernate:hibernate-java8")
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
//Spring cloud
compile("org.springframework.cloud:spring-cloud-spring-service-connector")
compile("org.springframework.cloud:spring-cloud-localconfig-connector")
compile("org.springframework.cloud:spring-cloud-cloudfoundry-connector")
// Relational Database
compile("org.postgresql:postgresql:${postgresqlVersion}")
compile("org.flywaydb:flyway-core")
// Connection pooling
compile("com.zaxxer:HikariCP")
//Shield
compile("org.elasticsearch.client:x-pack-transport:${elasticsearchVersion}")
compile("org.elasticsearch:elasticsearch:${elasticsearchVersion}")
compile("org.apache.logging.log4j:log4j-api")
compile("org.apache.logging.log4j:log4j-core")
// QueryDSL
compile("com.querydsl:querydsl-core:${queryDslVersion}")
compile("com.querydsl:querydsl-jpa:${queryDslVersion}")
compileOnly('org.projectlombok:lombok')
compileOnly('org.mapstruct:mapstruct-jdk8:1.2.0.Beta3')
apt "com.querydsl:querydsl-apt:${queryDslVersion}", 'org.mapstruct:mapstruct-processor:1.2.0.Beta3', 'org.projectlombok:lombok'
// Jackson
compile("com.fasterxml.jackson.core:jackson-core")
compile("com.fasterxml.jackson.core:jackson-annotations")
compile("org.apache.httpcomponents:httpclient:${httpClientVersion}")
compile("org.jasypt:jasypt:${jasyptVersion}")
}
sourceSets {
main {
output.dir("build/generated-mail-templates")
}
}
bootRepackage {
enabled = false
}
task npmInstall(type: Exec) {
description "npm install"
commandLine 'npm', 'install'
}
task processMailTemplates {
description "Processes mail templates"
dependsOn npmInstall
outputs.upToDateWhen { false }
doLast {
def templateSrcDir = "src/main/templates/mail/"
def templateDestDir = "build/generated-mail-templates/META-INF/templates/mail/"
mkdir templateDestDir
def templateNames = []
fileTree(dir: templateSrcDir, include: '**/*.html').visit {
FileVisitDetails details -> templateNames << details.file.name
}
templateNames.each { templateName -> inlineCss(templateSrcDir + templateName, templateDestDir + templateName) }
}
}
static def inlineCss(src, dest) {
def juice = 'node_modules/.bin/juice'
def juiceResourcesDir = 'src/main/templates/misc/'
def juiceArgs = "--options-file ${juiceResourcesDir}juiceOptions.json --css ${juiceResourcesDir}mailStyle.css"
"${juice} ${juiceArgs} ${src} ${dest}".execute(null, new File('bignibou-common'))
}
compileJava {
aptOptions.processors = ['com.querydsl.apt.jpa.JPAAnnotationProcessor']
}
processResources.dependsOn processMailTemplates
Here is the error I get:
> Task :bignibou-common:compileJava
Putting task artifact state for task ':bignibou-common:compileJava' into context took 0.001 secs.
Resolving dependency management for configuration 'apt' of project 'bignibou-common'
Resolving global dependency management for project 'bignibou-common'
Excluding []
Resolving dependency management for configuration 'compileClasspath' of project 'bignibou-common'
Resolving dependency management for configuration 'compileOnly' of project 'bignibou-common'
Resolving dependency management for configuration 'implementation' of project 'bignibou-common'
Resolving dependency management for configuration 'compile' of project 'bignibou-common'
Excluding []
Executing task ':bignibou-common:compileJava' (up-to-date check took 0.628 secs) due to:
Task ':bignibou-common:compileJava' has additional actions that have changed
All input files are considered out-of-date for incremental task ':bignibou-common:compileJava'.
Excluding []
Compiling with JDK Java compiler API.
Note: Running JPAAnnotationProcessor
:bignibou-common:compileJava (Thread[Task worker,5,main]) completed. Took 0.727 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bignibou-common:compileJava'.
> java.lang.NoClassDefFoundError: javax/persistence/Entity
Indicating that the javaCompile task has somehow lost the compile classpath...
Can someone please help?
edit: Taking into account Thomas Broyer's advice, I was able to come up with the following changes:
compileJava {
aptOptions.processors = ['com.querydsl.apt.jpa.JPAAnnotationProcessor', 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor', 'org.mapstruct.ap.MappingProcessor']
}
compileOnly('org.projectlombok:lombok')
compileOnly('org.mapstruct:mapstruct-jdk8:1.2.0.Beta3')
apt "com.querydsl:querydsl-apt:${queryDslVersion}"
apt "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final"
apt "org.mapstruct:mapstruct-processor:1.2.0.Beta3"
apt "org.projectlombok:lombok"
Notice the added hibernate-jpa-2.1-api apt dependency and the three explicit processors defined on the aptOptions.
Thanks a lot Thomas!
Apparently, with querydsl-apt, you need to add the additional dependencies required by the specific processor you're using; in this case you need to add the JPA API to the apt configuration.
Also, note that by configuring aptOptions.processors explicitly with only the QueryDSL processor, the Lombok and MapStruct processors won't run.

Resources