Gradle is not able to use dependencies from artifactory - gradle

This is the code I have written: Please be notified that the code is working when I enable the flatDir section (commented one in the code), but not working when I want to use Remote Artifactory repository (Means comment the flatDir part):
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'distribution'
buildDir = new File("$buildPath", project.name)
ext.distributionDir = new File(project.buildDir, 'distribution')
sourceSets {
//SourceSets
}
ext.sharedManifest = manifest {
//Manifests
}
tasks.withType(Jar) {
//Code to generate Jar Artifacts
}
// repositories {
// flatDir {
// dirs file("$dependencyPath"),
// }
// }
allprojects {
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'gradle-dev-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
resolve {
repository {
repoKey = 'gradle-dev'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
}
}
project(':projectName:ProjectComponent') {
sourceSets {
main {
java { include '/pathToCode/*' }
}
}
dependencies { compile (group: 'jcifs', name: 'jcifs', version: '1.1.11')}
//******* Publishing Component Jar (Build artifacts on Remote Repository) ********//
publishing.publications {
mavenJava(MavenPublication) {
groupId 'GroupID'
artifactId project.name
version = projVersion
from components.java
}
}
artifactoryPublish {
publications(publishing.publications.mavenJava)
}
}
Please suggest the solution.
Thanks! :-)

Related

No compileOnly configuration in the build.gradle but it is

I have the following error message during the build, but no compileOnly dependency in my build.gradle. Why it's happens, and how to solve?
Regards
Resolving dependency configuration 'compileOnly' is not allowed as it
is defined as 'canBeResolved=false'. Instead, a resolvable
('canBeResolved=true') dependency configuration that extends
'compileOnly' should be resolved.
buildscript {
ext.kotlin_version = '1.6.0'
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven {
url "https://plugins.gradle.org/m2/"
}
repositories {
flatDir {
dirs 'jars'
}
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id "org.jetbrains.intellij" version "1.10.1"
id "org.jetbrains.grammarkit" version "2020.1"
}
configurations {
configurations.implementation.setCanBeResolved(true)
}
group 'com.interfaced'
version '0.2.7'
apply plugin: 'kotlin'
apply plugin: 'org.jetbrains.intellij'
sourceSets {
all {
java.srcDirs += ['src/main/gen']
kotlin.srcDirs += ['src/main/kotlin']
resources.srcDirs = ['src/main/resources']
}
}
grammarKit {
jflexRelease = '1.7.0-2'
}
repositories {
mavenCentral()
maven {
url "https://cache-redirector.jetbrains.com/intellij-dependencies"
}
}
dependencies {
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib
compileClasspath group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.7.22'
compileClasspath files('jars/grammar-kit.jar')
compileClasspath group: 'junit', name: 'junit', version: '4.12'
compileClasspath "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
}
intellij {
version '2022.3'
}
import org.jetbrains.grammarkit.tasks.GenerateLexer
import org.jetbrains.grammarkit.tasks.GenerateParser
def GENERATE_GROUP = 'Generate'
task generateLexer(type: GenerateLexer) {
source = "src/main/grammar/BrightScript.flex"
targetDir = "src/main/gen/com/interfaced/brs/lang/lexer"
targetClass = "_BrsLexer"
skeleton = "src/main/grammar/idea-flex.skeleton"
purgeOldFiles = true
description = 'Generate Lexer Java sources for BrightScript'
group = GENERATE_GROUP
}
task generateParser(type: GenerateParser) {
source = "src/main/grammar/BrightScript.bnf"
targetRoot = 'src/main/gen'
pathToParser = 'src/main/gen/com/interfaced/brs/lang/BrsParser.java'
pathToPsiRoot = 'src/main/gen/com/interfaced/brs/lang/psi'
purgeOldFiles = true
description = 'Generate Parser Java sources for BrightScript'
group = GENERATE_GROUP
// patch up to date check
outputs.upToDateWhen { false }
}
compileKotlin {
kotlinOptions.jvmTarget = "17"
}
compileKotlin.dependsOn(generateLexer, generateParser)

Not able to download jar from Artifactory repository in gradle project

I want to connect to the Artifactory repository
https://www.artifactrepository.citigroup.net/artifactory/webapp/#/artifacts/browse/tree/General/
and download a jar using build.gradle.
I have 2 repository in my code, which I want to connect: one is local and is where I've download all Gradle related jars and the other is artifactory repository where I want to download TIBCO related jars.
but not able to connect to second repo
This is my build.gradle code
buildscript {
repositories {
maven {
url "${artifactory_contextUrl}/plugins-release"
}
maven {
url 'https://www.artifactrepository.citigroup.net/artifactory/maven-cto-dev-3rdpartymanual-local'
}
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.9')
}
}
allprojects {
apply plugin: 'artifactory'
apply plugin: 'maven'
group = 'com.citi.recon'
task wrapper(type: Wrapper) {
distributionUrl = "${artifactory_contextUrl}/simple/ext-release-local/org/gradle/services/distributions/gradle/1.9/gradle-1.9-bin.zip"
description = 'Generates gradlew[.bat] scripts'
gradleVersion = '1.9'
}
}
artifactory {
contextUrl = "${artifactory_contextUrl}" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'libs-release-local'
maven = true
}
}
resolve {
repository {
repoKey = 'repo'
maven = true
}
}
}

Unable to start EmbeddedWebApplicationContext - not a web app

Here is the build.gradle file. I have removed comments and sensitive data.
Still receiving the "missing EmbeddedServletContainerFactory Bean" error.
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url "https://plugins.gradle.org" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-
plugin:${springBootVersion}")
classpath("org.jfrog.buildinfo:build-info-extractor-gradle:4.5.4")
classpath("gradle.plugin.de.gliderpilot.gradle.semantic-
release:gradle-semantic-release-plugin:1.3.1")
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
{
exclude module: 'spring-boot-starter-tomcat'
}
runtime files ('/libs/ojdbc8.jar')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
plugins {
id "org.sonarqube" version "2.5"
id "com.gorylenko.gradle-git-properties" version "1.4.17"
id "de.gliderpilot.semantic-release" version "1.3.1"
}
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
sourceCompatibility = 1.8
group = 'com.usps.informed-delivery'
dependencies {
compile('org.springframework.boot:spring-boot-starter-activemq')
compile('org.springframework.boot:spring-boot-actuator-docs')
compile('org.springframework.boot:spring-boot-starter-aop')
compile('org.springframework.boot:spring-boot-starter-batch')
compile('org.springframework.boot:spring-boot-starter-cache')
compile('org.springframework.boot:spring-boot-starter-data-cassandra')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-redis')
compile('org.springframework.boot:spring-boot-starter-integration')
compile('org.springframework.batch:spring-batch-integration')
compile('org.springframework.integration:spring-integration-xml')
compile('org.springframework.integration:spring-integration-mail')
compile('org.springframework.integration:spring-integration-test')
compile('org.slf4j:slf4j-api')
compile('org.springframework.integration:spring-integration-java-dsl')
compile("org.springframework:spring-oxm")
compile("joda-time:joda-time")
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
compile('org.liquibase:liquibase-core')
compile('libs/ojdbc8.jar')
runtime('org.springframework.boot:spring-boot-devtools')
runtime('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.batch:spring-batch-test')
testCompile('org.springframework.integration:spring-integration-test')
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
artifactory {
contextUrl = 'http:whatever'
publish {
repository {
if (version.toString().endsWith("-SNAPSHOT")) {
repoKey = 'snapshots'
} else {
repoKey = 'releases'
}
username = ""
password = ""
}
defaults {
publications('mavenJava')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
resolve {
repoKey = 'jcenter'
username = ""
password = ""
}
}
sonarqube {
properties {
property "sonar.sourceEncoding", "UTF-8"
property "sonar.projectKey", "readers-digest-generator"
property "sonar.projectName", "Readers Digest Generator"
}
}
Posting the build.gradle file per request. I have tried to resolve by putting
spring.main.web-environment-=false in aplication.properties file and app.setWebEnvironment(false) in BatchApplication.java
Spring Boot assumes it's a web app unless you configure it otherwise. The documentation (found here https://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-boot-application.html#howto-create-a-non-web-application) illustrates that you can either configure your application to not be a web app either programatically via calling SpringApplication#s setWebEnvironment(false) or via setting the property spring.main.web-environment=false

Using S3 Bucket as Maven private repository with gradle

I am trying to use AWS S3 as a maven private repo..below is my build.gradle looks like-:
import java.util.regex.Matcher
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.amazonaws:aws-java-sdk-core:1.11.5'
}
}
plugins {
id "java"
id "idea"
id "eclipse" //run "./gradlew cleanEclipse eclipse" after importing to eclipse
id "maven-publish"
id "maven"
id 'base'
id 'signing'
id 'jacoco'
id "net.researchgate.release" version "2.4.1"
id "org.springframework.boot" version "1.5.2.RELEASE"
}
def fetchAwsCredentials = {
try {
return new ProfileCredentialsProvider().getCredentials()
} catch (Exception e) {
logger.debug('Unable to retrieve AWS credentials from profile, publishing to S3 will not be available.', e)
return null
}
}
AWSCredentials awsCredentials = fetchAwsCredentials()
repositories {
mavenCentral()
maven {
url 'xxxxxxxx/<Bucket-Name>/snapshots/'
credentials(AwsCredentials) {
accessKey awsCredentials.AWSAccessKeyId
secretKey awsCredentials.AWSSecretKey
}
}
}
publish {
dependsOn assemble
}
publishing {
publications {
maven(MavenPublication) {
groupId this.properties['group']
artifactId this.properties['mavenArtifactId']
from components.java
}
}
repositories {
maven {
name 'repo'
credentials(AwsCredentials) {
accessKey awsCredentials.AWSAccessKeyId
secretKey awsCredentials.AWSSecretKey
}
if (project.version.endsWith('-SNAPSHOT')) {
url "xxxxxxxx/<Bucket-Name>/snapshots/"
} else {
url "xxxxxxxx/<Bucket-Name>/releases/"
}
}
}
}
But I am getting below error
Caused by: java.lang.IllegalArgumentException: Credentials must be an instance of: org.gradle.api.artifacts.repositories.PasswordCredentials
at org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory.convertPasswordCredentials(RepositoryTransportFactory.java:87)
at org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory.access$100(RepositoryTransportFactory.java:39)
at org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory$DefaultResourceConnectorSpecification.getCredentials(RepositoryTransportFactory.java:136)
at org.gradle.internal.resource.transport.http.HttpConnectorFactory.createResourceConnector(HttpConnectorFactory.java:36)
at org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory.createTransport(RepositoryTransportFactory.java:101)
at org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory.createTransport(RepositoryTransportFactory.java:79)
at org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.getTransport(DefaultMavenArtifactRepository.java:122)
at org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.createResolver(DefaultMavenArtifactRepository.java:109)
at org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.createRealResolver(DefaultMavenArtifactRepository.java:100)
at org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.createResolver(DefaultMavenArtifactRepository.java:91)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ResolveIvyFactory.create(ResolveIvyFactory.java:92)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver$1.execute(DefaultDependencyResolver.java:92)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver$1.execute(DefaultDependencyResolver.java:90)
at org.gradle.internal.Transformers$4.transform(Transformers.java:137)
at org.gradle.api.internal.artifacts.ivyservice.DefaultIvyContextManager.withIvy(DefaultIvyContextManager.java:61)
at org.gradle.api.internal.artifacts.ivyservice.DefaultIvyContextManager.withIvy(DefaultIvyContextManager.java:39)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver.resolve(DefaultDependencyResolver.java:90)
at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver$1.run(CacheLockingArtifactDependencyResolver.java:42)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:192)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:175)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:106)
at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.useCache(DefaultCacheFactory.java:187)
at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.useCache(DefaultCacheLockingManager.java:64)
at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver.resolve(CacheLockingArtifactDependencyResolver.java:40)
at org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver.resolve(SelfResolvingDependencyResolver.java:45)
at org.gradle.api.internal.artifacts.ivyservice.ShortcircuitEmptyConfigsArtifactDependencyResolver.resolve(ShortcircuitEmptyConfigsArtifactDependencyResolver.java:58)
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.resolve(ErrorHandlingArtifactDependencyResolver.java:47)
... 81 more
Looks like it failing because of incorrect condition added in gradle jar-:
https://github.com/gradle/gradle/blob/master/subprojects/resources-http/src/main/java/org/gradle/internal/resource/transport/http/HttpClientConfigurer.java
Any Clue ?
The problem you are facing is for wrong S3 Url pattern.
There are two interfaces extends from base Credentials interface.
AwsCredentials
PasswordCredentials
When you used url 'xxxxxxxx/<Bucket-Name>/snapshots/', it detects the maven repo as just normal url. That is why it was asking for PasswordCredentials.
You should use s3://<bucket-name>.s3-eu-west-1.amazonaws.com. Here it will ask for AwsCredentials.
IMHO you should use two different buckets for releases and snapshots.
repositories {
maven {
name 'repo'
credentials(AwsCredentials) {
accessKey awsCredentials.AWSAccessKeyId
secretKey awsCredentials.AWSSecretKey
}
if (project.version.endsWith('-SNAPSHOT')) {
url "s3://<bucket-name>-snapshots.s3-eu-west-1.amazonaws.com"
} else {
url "s3://<bucket-name>-releases.s3-eu-west-1.amazonaws.com"
}
}
}

Gradle artifactory plugin cannot resolve dependency on configuration phase

I am trying to resolve dependency in configuration phase with artifactory gradle plugin.
apply plugin: 'java'
apply plugin: 'com.jfrog.artifactory'
artifactory {
contextUrl = "${artifactory_contextUrl}"
...
resolve {
repository {
repoKey = 'repo'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
dependencies {
compile 'commons-lang:commons-lang:+'
}
task testCustomResolve {
logger.quiet configurations.getByName('compile').singleFile.absolutePath
}
And it gives me
Could not resolve all dependencies for configuration ':compile'.
Cannot resolve external dependency commons-lang:commons-lang:+ because no repositories are defined.
It works as a charm in execution phase
task testCustomResolve << {
logger.quiet configurations.getByName('compile').singleFile.absolutePath
}
or when I use mavenCentral()
repositories {
mavenCentral()
}
In case you don't need to publish to Artifactory, I noticed that it works better if you don't use the artifactory {} syntax. Instead, try using:
plugins {
id "com.jfrog.artifactory" version "4.4.10"
}
repositories {
mavenLocal()
maven {
url "${artifactory_contextUrl}/${artifactory_repo}"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
mavenCentral()
}

Resources