No method found while using com.jfrog.artifactory plugin - java

I am new to gradle please pardon my ignorance. Have a basic gradle project.
I get the following error when I run ./gradlew tasks
FAILURE: Build failed with an exception.
* Where:
Build file '<path>/build.gradle' line: 17
* What went wrong:
> No signature of method: build_204u1riu5haork78eb2ib9dc1t$_run_closure2.id() is applicable for argument types: (java.lang.String) values: [com.jfrog.artifactory]
Possible solutions: is(java.lang.Object), is(java.lang.Object), find(), find(), find(groovy.lang.Closure), find(groovy.lang.Closure)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Following is my build.gradle
buildscript {
repositories {
maven {
url '<URL>'
credentials {
username = "<USERNAME>"
password = "<PASSWORD>"
}
}
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.9')
}
}
plugins {
id "com.jfrog.artifactory" version "3.0.1" //<=== LINE 17
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'application'
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
artifactory {
contextUrl = "<URL>"
publish {
repository {
repoKey = 'libs-snapshot-local'
username = "<USERNAME>"
password = "<PASSWORD>"
maven = true
}
defaults {
publications('mavenJava')
}
}
resolve {
repository {
repoKey = 'libs-all'
username = "<USERNAME>"
password = "<PASSWORD>"
maven = true
}
}
}
allprojects {
repositories {
mavenCentral()
}
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.7'
compile 'org.slf4j:slf4j-simple:1.7.7'
compile 'com.amazonaws:aws-java-sdk:1.9.38'
testCompile 'junit:junit:4.11'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2'
}
I am sure it is a very basic issue which is why when I googled around, did not find any solutions. Would be great if someone could point me in the right direction or share a link to any previous related issues.

This can happen if you are building using Gradle 1.x. The Gradle plugins DSL was introduced in Gradle 2.1 and is not supported by older Gradle version.
You have gradle wrapper configured to use Gradle 2.2, but you need to make sure you are using the gradlew script instead of gradle

Another possibility is if you have any module in your project which has lower version gradle tools
e.g my app module had below build tools as dependency in buildscript
classpath 'com.android.tools.build:gradle:2.3.2'
but I had another module with below build tools as dependency in buildscriptclasspath 'com.android.tools.build:gradle:2.2.0'
In this situation I got below error
No signature of method: org.jfrog.gradle.plugin.artifactory.extractor.listener.ProjectsEvaluatedBuildListener$_projectsEvaluated_closure1.doCall() is applicable for argument types: (org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask_Decorated) values: [task ':uid:artifactoryPublish']
Then after changing
classpath 'com.android.tools.build:gradle:2.2.0' to classpath 'com.android.tools.build:gradle:2.3.2' everything worked well.

Related

Why can't Gradle find existing artifact?

I posted the same question at the Gradle Forums Gradle can not find existing artifact?.
Gradle v4.10.2
This really bothers me, since I know it should work, and I feel like I’m setting up my build.gradle file correctly.
I built a plugin and deployed it to our AWS S3 Maven repo.
When I run a Gradle command, e.g., ./gradlew clean, I get
Here's my build.gradle file
buildscript {
repositories {
maven {
url s3_bucket
credentials(AwsCredentials) {
accessKey AWS_ACCESS_KEY
accessKey AWS_SECRET_KEY
}
}
}
dependencies {
classpath "com.zift.utilities:zift-version-plugin:0.0.1"
}
}
plugins {
id 'java'
id 'maven'
id 'maven-publish'
id 'java-gradle-plugin'
}
version = '0.0.1'
jar {
manifest {
attributes 'artifactId': project.artifactId,
'groupId': project.groupId,
'version': project.version
}
baseName artifactId
doLast {
println "artifactId: $project.artifactId\ngroupId: $project.groupId\nversion: $version"
}
}
If I comment out the classpath line (the problematic line), I get
$ ./gradlew build
> Task :jar
:jar: No valid plugin descriptors were found in META-INF/gradle-plugins
artifactId: zift-version-plugin
groupId: com.zift.utilities
version: 0.0.1
What am I missing?

How to build not executable jar (library) with Spring Boot Gradle Plugin 2.1.*

I'm trying to build a library. I have Spring Boot Gradle Plugin in my build.gradle file:
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
}
My library without the main class. To prevent 'Main class not configured ...' error I add to build.gradle:
bootRepackage {
enabled = false
}
but got an error:
A problem occurred evaluating root project 'mysuperlibrary'.
Could not find method bootRepackage() for arguments [build_3886uiniuyuorta9lpa9n4f5c$_run_closure3#1975ec48] on root
project 'mysuperlibrary' of type org.gradle.api.Project.
All works fine with Spring boot Gradle Plugin 1.5.16 but don't works with 2.1.3.
UPDATE: This plugin I use because without it I can`t resolve testCompile 'org.springframework.boot:spring-boot-starter-test' . When I delete the plugin I can build project bit dependency for test disappears.
Now I'm using spring plugin with 2.1.* version in all my libs. It is necessary to add next before 'dependencies' section:
bootJar {
enabled = false
}
jar {
enabled = true
}
Update:
Just remove the plugin and add the testing dependencies directly. E.g. with JUnit 5:
dependencies {
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.1'
....
testImplementation(
"org.junit.jupiter:junit-jupiter-api:$jUnitVersion",
"org.junit.jupiter:junit-jupiter-params:$jUnitVersion"
)
testRuntimeOnly(
"org.junit.jupiter:junit-jupiter-engine:$jUnitVersion"
)
test {
useJUnitPlatform()
}
}
Old (suited for multi modul project):
You can use the apply flag:
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE' apply: false
}
and write a function
def isAbstract(project) {
return ['mysuperlibrary'].contains(project.name)
}
subprojects { project ->
if (isAbstract(project) {
return
}
apply plugin: 'org.springframework.boot'
}
May be like this:
tasks {
bootJar { mainClassName = "NONE" }
}

Why did heroku build fail with gradle and spring boot?

I'm trying to set basic workspace for Spring boot and gradle.
Everything works perfectly in local and in travis, but in heroku build fails. I don't think the problem is in the actual code, but in the configuration.
Here is my project in github.
build.gradle
plugins {
id 'java'
id 'maven'
id 'jacoco'
id 'org.springframework.boot' version '1.5.3.RELEASE'
}
group = 'org.karlin'
version = '0.1.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
bootRepackage {
mainClass = 'gramise.Gramise'
}
repositories {
maven {
url("https://plugins.gradle.org/m2/")
}
}
dependencies {
compile("com.google.code.gson:gson")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.postgresql:postgresql")
compile("org.apache.commons:commons-dbcp2")
compile("com.h2database:h2")
testCompile(group: 'org.springframework.boot', name: 'spring-boot-
starter-test', version:'1.5.3.RELEASE') {
exclude(module: 'commons-logging')
}
testCompile group: 'com.jayway.jsonpath', name: 'json-path', version:'2.2.0'
}
task stage(dependsOn: ['build', 'clean'])
build.mustRunAfter clean
There is heroku build log
-----> Gradle app detected
-----> Installing OpenJDK 1.8... done
-----> Installing Gradle Wrapper...
WARNING: Your application does not have it's own gradlew file.
-----> Building Gradle app...
-----> executing ./gradlew build
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/1.5.3.RELEASE/spring-boot-gradle-plugin-1.5.3.RELEASE.pom
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-tools/1.5.3.RELEASE/spring-boot-tools-1.5.3.RELEASE.pom
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-loader-tools/1.5.3.RELEASE/spring-boot-loader-tools-1.5.3.RELEASE.pom
Download https://plugins.gradle.org/m2/io/spring/gradle/dependency-management-plugin/1.0.2.RELEASE/dependency-management-plugin-1.0.2.RELEASE.pom
Download https://plugins.gradle.org/m2/org/springframework/spring-core/4.3.8.RELEASE/spring-core-4.3.8.RELEASE.pom
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/1.5.3.RELEASE/spring-boot-gradle-plugin-1.5.3.RELEASE.jar
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-loader-tools/1.5.3.RELEASE/spring-boot-loader-tools-1.5.3.RELEASE.jar
Download https://plugins.gradle.org/m2/io/spring/gradle/dependency-management-plugin/1.0.2.RELEASE/dependency-management-plugin-1.0.2.RELEASE.jar
Download https://plugins.gradle.org/m2/org/springframework/spring-core/4.3.8.RELEASE/spring-core-4.3.8.RELEASE.jar
FAILURE: Build failed with an exception.
* What went wrong:
org/gradle/api/plugins/JavaPlugin
> org.gradle.api.plugins.JavaPlugin
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
You need to check gradlew into Git.
WARNING: Your application does not have it's own gradlew file.
Because you are not doing this, Heroku is using a very old version of Gradle.
If someone else is encountering this problem, this fixed it
I added buildscript in build.gradle
buildscript {
ext {
springBootVersion = '1.5.3.RELEASE'
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/libs-snapshot' }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
Now everything is working, thanks for help.

org.gradle.initialization.DefaultSettings_Decorated cannot be cast to org.gradle.api.internal.project.ProjectInternal

I tried to create spring boot application:
I selected components I need from https://start.spring.io/
Now I want to build the application and it fall downs:
FAILURE: Build failed with an exception.
* Where:
Settings file 'D:\objectsharingsystem\settings.gradle' line: 2
* What went wrong:
A problem occurred evaluating settings 'object-sharing-system'.
> Failed to apply plugin [id 'org.gradle.java']
> org.gradle.initialization.DefaultSettings_Decorated cannot be cast to org.gradle.api.internal.project.ProjectInternal
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
settings.gradle:
rootProject.name = 'object-sharing-system'
apply plugin: 'java'
compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
build.gradle:
buildscript {
ext {
springBootVersion = '2.0.0.BUILD-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-validation')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('com.microsoft.sqlserver:mssql-jdbc')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Please help to find mistake.
settings.gradle can not handle application of Project level plugin.
Remove apply plugin and compileJava from settings.gradle.
You already have your sourceCompatibility set in build.gradle
See here where it says
method calls within the settings file is delegated to a settings object. Look at the Settings class in the API documentation for more information.
Unlike build.gradle, the apply method in settings.gradle expects a Plugin<Settings> and not a Plugin<Project>. The java plugin is a Plugin<Project> and can't be applied like this in settings.gradle

Running Flyway migrations on gradle refresh

I am still trying to wrap my head around gradle so please bear with me.
I'm trying to set up flyway migrations to run automatically on every gradle refresh/build instead of having to run a command-line command. So when someone is pulling the latest changes including some new migrations their local db will be up to date.
I have this build.grade in the root dir:
buildscript {
...
repositories {
mavenLocal()
mavenCentral()
}
allprojects {
...
}
project(":core") {
apply plugin: "java"
dependencies {
compile project(":shared")
}
}
project(":server") {
apply plugin: "java"
dependencies {
compile project(":shared")
}
}
project(":shared") {
apply plugin: "java"
}
tasks.eclipse.doLast {
delete ".project"
}
Where I've tried merging the lines from the flyway get started pages.
I basically want to run the $ gradle flywayMigrate -i command from within the build.gradle file. I've tried with build.finalizedBy(flywayMigrate) but to no avail.
How would I do something like that?
Thanks in advance!
In order to make build finalized by flywayMigrate you need to run gradle build which probably You didn't.
To run flywayMigrate you can use defaultTasks which will run the tasks configured if no other are provided. So:
buildscript {
dependencies {
classpath 'com.h2database:h2:1.4.191'
}
}
plugins {
id "org.flywaydb.flyway" version "4.1.2"
}
flyway {
url = 'jdbc:h2:file:./target/foobar'
user = 'sa'
}
defaultTasks 'flywayMigrate'
When it comes to configuring -i (logging level) from within build.gradle it seems to be impossible with the newest gradle versions.

Categories