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.
Related
I am trying to run simply the Gluon single scene example. Here is my gradle output:
Configuration on demand is an incubating feature.
> Configure project :GluonApplicationApp
Project :GluonApplicationApp => no module-info.java found
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':GluonApplicationApp'.
> Could not create task ':GluonApplicationApp:debug'.
> Unnecessarily replacing a task that does not exist is not supported. Use create() or register() directly instead. You attempted to replace a task named 'debug', but there is no existing task with that name.
* 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
My build.gradle:
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 = 'com.gluonapplication.GluonApplication'
dependencies {
compile 'com.gluonhq:charm:5.0.2'
}
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'
}
}
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'org.openjfx:javafx-plugin:0.0.9'
}
}
apply plugin: 'org.openjfx.javafxplugin'
The JDK version i'm using is JDK 11, and I have tried various gradle versions. For my IDE I use netbeans.
I have been trying to fix this all day. Please help
I was using the old Gluon IDE plugin
Gluon build 0.1.29-SNAPSHOT fixes the rest of the problems
More details on comments of the question!
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.
When I do a
gradle android
with the jfxmobile-plugin on my JavaFX-application I get
...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':mergeClassesIntoJar'.
> archive contains more than 65535 entries.
To build this archive, please enable the zip64 extension.
See: https://docs.gradle.org/3.2.1/dsl/org.gradle.api.tasks.bundling.Zip.html#org.gradle.api.tasks.bundling.Zip:zip64
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
The gradle file looks like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.2'
}
}
apply plugin: 'org.javafxports.jfxmobile'
mainClassName = 'de.package.of.application.ClientApp'
dependencies {
compile 'com.annimon:stream:1.0.1'
compile 'com.jakewharton.threetenabp:threetenabp:1.0.4'
compile 'com.gluonhq:charm:3.0.0'
androidRuntime 'com.gluonhq:charm-android:3.0.0'
iosRuntime 'com.gluonhq:charm-ios:3.0.0'
desktopRuntime 'com.gluonhq:charm-desktop:3.0.0'
compile fileTree(dir: 'target/dependencies', include: '*.jar')
runtime fileTree(dir: 'target/dependencies', include: '*.jar')
}
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
jfxmobile {
ios {
forceLinkClasses = ['ensemble.**.*']
}
android {
applicationPackage = 'org.javafxports.ensemble'
compileSdkVersion = '21'
androidSdk='C:/Tools/android-sdk-windows'
}
}
Over the last years since Javafx exists the application has become, I would say, a 'bigger' one; a fat-client with many own classes but also many third-party dependencies.
I found an article about the jfxmobile-plugin and thought 'Why not give it a try?'. The current issue is the one described in this question.
I already stripped down the application to reduce classes to a minimum so the application still makes some sense in some way but it does not help.
Does anyone have a suggestions how to solve it?
I am a new to Java, Gradle and Spring.
I setup a new project with the following gradle script:
buildscript {
repositories {
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.0.BUILD-SNAPSHOT")
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
repositories {
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
When trying to build with the above script, I get the following errors:
E:\Projects\SpringAppTutorial>gradlew
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'SpringAppTutorial'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.3.0.BUILD-SNAPSHOT.
Required by:
:SpringAppTutorial:unspecified
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.3.0.BUILD-SNAPSHOT.
> Could not parse POM http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-gradle-plugin/1.3.0.BUILD-SNAPSHOT/spring-boot-gradle-plugin-1.3.0.BUILD-20150531.081700-179.pom
> Could not resolve org.springframework.boot:spring-boot-tools:1.3.0.BUILD-SNAPSHOT.
> Could not resolve org.springframework.boot:spring-boot-tools:1.3.0.BUILD-SNAPSHOT.
> Could not parse POM http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-tools/1.3.0.BUILD-SNAPSHOT/spring-boot-tools-1.3.0.BUILD-20150531.081700-180.pom
> Could not resolve org.springframework.boot:spring-boot-parent:1.3.0.BUILD-SNAPSHOT.
> Could not resolve org.springframework.boot:spring-boot-parent:1.3.0.BUILD-SNAPSHOT.
> Could not parse POM http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-parent/1.3.0.BUILD-SNAPSHOT/spring-boot-parent-1.3.0.BUILD-20150531.081700-180.pom
> Could not resolve org.springframework.boot:spring-boot-dependencies:1.3.0.BUILD-SNAPSHOT.
> Could not resolve org.springframework.boot:spring-boot-dependencies:1.3.0.BUILD-SNAPSHOT.
> Could not parse POM http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-dependencies/1.3.0.BUILD-SNAPSHOT/spring-boot-dependencies-1.3.0.BUILD-20150531.081700-181.pom
> Could not find org.springframework.data:spring-data-releasetrain:Fowler-RELEASE.
Searched in the following locations:
http://repo.spring.io/snapshot/org/springframework/data/spring-data-releasetrain/Fowler-RELEASE/spring-data-releasetrain-Fowler-RELEASE.pom
http://repo.spring.io/snapshot/org/springframework/data/spring-data-releasetrain/Fowler-RELEASE/spring-data-releasetrain-Fowler-RELEASE.jar
http://repo.spring.io/milestone/org/springframework/data/spring-data-releasetrain/Fowler-RELEASE/spring-data-releasetrain-Fowler-RELEASE.pom
http://repo.spring.io/milestone/org/springframework/data/spring-data-releasetrain/Fowler-RELEASE/spring-data-releasetrain-Fowler-RELEASE.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 15.726 secs
E:\Projects\SpringAppTutorial>
What am I doing wrong here?
You should be using a release version of the spring-boot gradle plugin - your script is using a development snapshot version string of some kind.
i.e. try
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
}
(from http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html)
Assuming that works, you should be able to get rid of this section also:
repositories {
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
I have faced the same problem and as #skaffman suggests, I added version to my dependencies, it resolved.
implementation('org.springframework.session:spring-session:1.3.4.RELEASE')
runtimeOnly('com.okta.spring:okta-spring-boot-starter:0.6.1')
runtimeOnly('org.springframework.security.oauth:spring-security-oauth2:2.3.4.RELEASE')
I have a custom gradle plugin in which custom task types and gradle configurations are added. When I apply this plugin before maven-publish it works perfectly fine. But when I add it after apply plugin: 'maven-publish', it fails with error message :
FAILURE: Build failed with an exception.
* Where:
Build file '/scratch/skgupta/git_storage/emdi/integtest/build.gradle' line: 38
* What went wrong:
A problem occurred evaluating root project 'integtest'.
> Cannot configure the 'publishing' extension after it has been accessed.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 7.6 secs
Here is the build.gradle file.
buildscript {
repositories {
maven {
url = "${artifactory_contextUrl}/repo"
}
}
dependencies {
classpath group: 'com.mycomp.proj', name: 'MyCustomPlugin', version: "${pluginVersion}", transitive: true
}
}
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'MyCustomPlugin' // WHen this line is moved above maven-publish, build works fine.
// add jar name and version
jar.archiveName='lrgemaas_small_deploy_3n.jar'
group = 'com.mycom.proj.test'
version = '1.0.3'
dependencies {
compile group: 'eaas.platform', name: 'registry-lookup-client', version: '0.1'
compile group: 'eaas.platform', name: 'registry-client', version: '0.1'
compile configurations.lrgConfig // This configuration is added by MyCustomPlugin
compile configurations.webdriver // This configuration is added by MyCustomPlugin
}
repositories {
maven {
url = "${artifactory_contextUrl}/repo"
}
}
publishing {
publications {
myPublicationName(MavenPublication) {
artifactId 'lrgemaas_small_deploy_3n'
artifact jar.archivePath
}
}
repositories {
maven {
url = "${artifactory_contextUrl}/${artifactory_repoName}"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
}
// workflow for build
defaultTasks 'clean','build','publish'
PS: I tried doing nothing in the custom plugin (i.e., simply return from apply method), but it still gives same error.
Simply replacing:
publishing {
publications {
...
}
}
with following:
publishing.publications {
...
}
worked for me!
Gradle is brittle regarding the order of the plugins. There is a discussion about this exact issue at
https://discuss.gradle.org/t/apply-maven-publish-plugin-from-init-script/2460
"Cool, so this is what happens.
DefaultPublishingExtension which is backing the 'publishing {}' block is a DeferredConfigurable. It's a mechanism that allows to register a configuration block to be executed when an extension is accessed. Unfortunately sometimes it causes unexpected behaviour if you access this kind of extension unawares. This is exactly the case when for example you try to get all the properties of a project (as the release plugin does here: https://github.com/townsfolk/gradle-release/blob/master/src/main/groovy/release/PluginHelper.groovy#L230"
FYI, I use a dynamic version and found that I had to define version prior to apply of my plugins. Probably because java or maven-publish sets the publication details upon application.
I upgraded gradle version from 2.1 to 2.12 and it solved this problem, fwiw.