Artifactory + Custom Gradle Plugin Programmatically - groovy

I am writing a custom plugin to eliminate the need for:
artifactory {
contextUrl = "${artifactory_contextUrl}" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
contextUrl = "${artifactory_contextUrl}"
repoKey = 'android-dev'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
resolve {
repository {
contextUrl = "${artifactory_contextUrl}"
repoKey = 'android-dev-distributions'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
Here is how I am doing this programmatically:
DefaultExtraPropertiesExtension ext = (((DefaultExtraPropertiesExtension) project.property("ext")));
ext.setProperty("artifactory", new ArtifactoryDsl(contextUrl, publish, resolve));
This should work, correct? The ArtifactoryDsl object has all of the correct fields (contextUrl, publish, resolve with their respective inner fields).
This is the error:
14:46:49.752 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.lang.IllegalStateException: Context URL cannot be empty
14:46:49.753 [ERROR] [org.gradle.BuildExceptionReporter] at org.jfrog.build.client.ArtifactoryClientConfiguration.getContextUrl(ArtifactoryClientConfiguration.java:111)
14:46:49.754 [ERROR] [org.gradle.BuildExceptionReporter] at org.jfrog.build.client.ArtifactoryClientConfiguration$PublisherHandler.getContextUrl(ArtifactoryClientConfiguration.java:225)
14:46:49.754 [ERROR] [org.gradle.BuildExceptionReporter] at org.jfrog.gradle.plugin.artifactory.extractor.BuildInfoTask.prepareAndDeploy(BuildInfoTask.java:526)
14:46:49.755 [ERROR] [org.gradle.BuildExceptionReporter] at org.jfrog.gradle.plugin.artifactory.extractor.BuildInfoTask.collectProjectBuildInfo(BuildInfoTask.java:440)
14:46:49.755 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
14:46:49.755 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:219)
14:46:49.756 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
14:46:49.756 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
14:46:49.757 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:533)
14:46:49.757 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:516)
14:46:49.758 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
14:46:49.777 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
14:46:49.778 [ERROR] [org.gradle.BuildExceptionReporter] ... 66 more

No, this isn't going to work. Your plugin will have to apply the Artifactory plugin, then get the artifactory object using project.artifactory (Groovy) or project.getExtensions().getByName("artifactory") (Java), then configure that object.

For anyone who is curious how to achieve this, I had done it this way:
In your build.gradle ensure you can access Artifactory classes:
compile "org.jfrog.buildinfo:build-info-extractor-gradle:2.2.4"
Next in your custom plugin's apply() method:
// Set up plugins so we never need to add them to a build.gradle
project.getPlugins().apply(MAVEN);
project.getPlugins().apply(ARTIFACTORY);
project.setGroup(GROUP);
// Add Artifactory repo to the repositories
project.getRepositories().maven(new ArtifactoryAction(contextUrl + ARTIFACTORY_REPO_ENDPOINT, user, pass));
// We will define the plugin convention here so all of our libraries do not need to
// declare the artifactory closure manually
ArtifactoryPluginConvention pluginConvention =
ArtifactoryPluginUtil.getArtifactoryConvention(project);
pluginConvention.setContextUrl(contextUrl);
PublisherConfig publisherConfig = new PublisherConfig(pluginConvention);
publisherConfig.setContextUrl(contextUrl);
pluginConvention.setPublisherConfig(publisherConfig);
// Use reflection to access private field
PublisherConfig.Repository repository = null;
Field[] fields = PublisherConfig.class.getDeclaredFields();
for(Field field : fields) {
if(field.getName().equalsIgnoreCase("repository")) {
try {
field.setAccessible(true);
repository = (PublisherConfig.Repository) field.get(publisherConfig);
} catch (Exception e) {
e.printStackTrace();
}
}
}
if(repository != null) {
repository.setPassword(pass);
repository.setUsername(user);
repository.setRepoKey(PUBLISHER_REPO_KEY);
repository.setMavenCompatible(true);
}
GradleArtifactoryClientConfigUpdater.update(pluginConvention.getClientConfig(), project.getRootProject());

Thanks a lot #agrosner, i was looking for a very long time as well and your answer saved my day !
For anyone that wants to implement their plugin with groovy, here is my implementation based on the previous post:
PS: I'm using org.jfrog.buildinfo:build-info-extractor-gradle:4.9.8 and mave-publish
PS 2: For some reason it was necessary to apply maven to the root project as well as. otherwise you had the error Extension of type 'PublishingExtension' does not exist. Currently registered extension types: [ExtraPropertiesExtension]
class Plugin implements Plugin<Project> {
#Override
void apply(Project project) {
//Maven publication plugin needs to be applied to root also
project.rootProject.pluginManager.apply "maven-publish"
project.pluginManager.apply "maven-publish"
project.plugins.apply "com.jfrog.artifactory"
def artifactory_contextUrl = project.artifactory_contextUrl
def artifactory_writer_user = project.artifactory_writer_user
def artifactory_writer_password = project.artifactory_writer_password
// We will define the plugin convention here so all of our libraries do not need to
// declare the artifactory closure manually
ArtifactoryPluginConvention pluginConvention = ArtifactoryPluginUtil.getArtifactoryConvention(project)
//uses closures to set the configuration
pluginConvention.artifactory {
contextUrl = "${artifactory_contextUrl}"
publish{
repository {
repoKey = 'repo name here'
username = "${artifactory_writer_user}"
password = "${artifactory_writer_password}"
maven = true
}
defaults {
publications('plugin')
}
}
}
//commits changes
GradleArtifactoryClientConfigUpdater.update(pluginConvention.clientConfig, project.rootProject)
}
}

Related

Liquibase Hibernate missing SequenceStyleGenerator.generatorKey() error

I am trying to generate a diff changelog using Liquibase and Hibernate but when I run the command gradle diffChangeLog I get the following error:
ERROR [liquibase.integration.commandline.Main]: Unexpected error running Liquibase: 'java.lang.Object org.hibernate.id.enhanced.SequenceStyleGenerator.generatorKey()'
java.lang.NoSuchMethodError: 'java.lang.Object org.hibernate.id.enhanced.SequenceStyleGenerator.generatorKey()'
I am able to generate a changelog, but only get issues when trying to generate a diff changelog. My build.gradle.kts file is below:
plugins {
java
id("org.springframework.boot") version "2.6.2"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id("org.liquibase.gradle") version "2.1.1"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
var sourceCompatibility = "11"
val postgresVersion = "42.2.19"
val liquibaseVersion = "2.1.1"
val lombokVersion = "1.18.20"
val liquibaseCoreVersion = "3.8.4"
val liquibaseExtVersion = "5:3.8"
val hibernateCoreVersion= "5.4.10.Final"
repositories {
mavenCentral()
maven {
url = uri("https://repo.spring.io/milestone")
}
maven {
url = uri("https://repo.spring.io/snapshot")
}
}
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath("net.ltgt.gradle:gradle-apt-plugin:0.18")
classpath("org.postgresql:postgresql:42.2.9")
classpath("org.liquibase.ext:liquibase-hibernate5:3.8")
classpath("org.liquibase:liquibase-core:3.8.4")
classpath("org.liquibase:liquibase-gradle-plugin:2.0.2")
classpath("org.springframework.data:spring-data-jpa:2.2.1.RELEASE")
}
}
dependencies {
implementation("org.jetbrains:annotations:20.1.0")
runtimeOnly("org.postgresql:postgresql")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
// implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.postgresql:postgresql:$postgresVersion")
implementation("org.springframework.boot:spring-boot-starter")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group= "junit", module= "junit")
}
//testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.hamcrest:hamcrest-library:2.2")
implementation("org.liquibase:liquibase-core:$liquibaseCoreVersion")
implementation("org.liquibase.ext:liquibase-hibernate$liquibaseExtVersion")
implementation("org.springframework.boot:spring-boot:2.6.2")
implementation("info.picocli:picocli:4.6.1")
implementation("org.liquibase:liquibase-groovy-dsl:3.0.0")
liquibaseRuntime("org.liquibase:liquibase-core:$liquibaseCoreVersion")
liquibaseRuntime("org.liquibase:liquibase-groovy-dsl:2.1.1")
liquibaseRuntime("org.postgresql:postgresql:$postgresVersion")
liquibaseRuntime("org.liquibase.ext:liquibase-hibernate$liquibaseExtVersion")
liquibaseRuntime(sourceSets.getByName("main").compileClasspath)
liquibaseRuntime(sourceSets.getByName("main").runtimeClasspath)
liquibaseRuntime(sourceSets.getByName("main").output)
compileOnly("org.projectlombok:lombok:$lombokVersion")
annotationProcessor("org.projectlombok:lombok:$lombokVersion")
}
tasks.named<Test>("test") {
useJUnitPlatform()
}
tasks {
// Use the native JUnit support of Gradle.
"test"(Test::class) {
useJUnitPlatform()
}
}
liquibase {
activities.register("main") {
this.arguments = mapOf(
"classpath" to "src/main/resources",
"driver" to "org.postgresql.Driver",
"logLevel" to "info",
"changeLogFile" to "src/main/resources/db/changelog/changes/changelog_002.xml",
"url" to "jdbc:postgresql://localhost:54320/postgres?currentSchema=schema",
"username" to "postgres",
"password" to "postgres",
"referenceUrl" to "hibernate:spring:com.example?dialect=org.hibernate.dialect.PostgreSQLDialect" +
"&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate." +
"SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=" +
"org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy")
}
}
I have tried to change the versioning around but then get an error saying the driver could not be found.
Any help would be greatly appreciated! Thank you

Getting could not resolve all artifact error at application run

Recently after upgrading android studio 4.1 my app started to stuck in "running gradle task assembledebug" so i checked the web for possible solution
Tried flutter clean and gradle commands changed gradle files but nothing worked finally deleted gradle and reinstalled android studio again but now i can't get android sdk 28 to be installed (it doesnt appear in sdk list) so i changed sdk to 29 but whenever i try to run my app it gives the fallowing errors
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:3.5.3.
Required by:
project :
> Could not resolve com.android.tools.build:gradle:3.5.3.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.5.3/gradle-3.5.3.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.5.3/gradle-3.5.3.pom'.
> Connect to localhost:3128 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
> Could not resolve com.android.tools.build:gradle:3.5.3.
> Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.5.3/gradle-3.5.3.pom'.
> Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.5.3/gradle-3.5.3.pom'.
> Connect to localhost:3128 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
> Could not resolve com.google.gms:google-services:4.3.4.
Required by:
project :
> Could not resolve com.google.gms:google-services:4.3.4.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.4/google-services-4.3.4.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.4/google-services-4.3.4.pom'.
> Connect to localhost:3128 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
> Could not resolve com.google.gms:google-services:4.3.4.
> Could not get resource 'https://jcenter.bintray.com/com/google/gms/google-services/4.3.4/google-services-4.3.4.pom'.
> Could not GET 'https://jcenter.bintray.com/com/google/gms/google-services/4.3.4/google-services-4.3.4.pom'.
> Connect to localhost:3128 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
* 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
BU�LD FAILED in 1m 24s
Exception: Gradle task assembleDebug failed with exit code 1
My current project level build gradle file is like this.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms:google-services:4.3.4'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App lvl build gradle file is like this:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 29
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.farukdurusoy.sayi_avi"
minSdkVersion 16
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
apply plugin: 'com.google.gms.google-services'
Also disabled my firewalls. Any suggestions?

Spring cloud AWS kinesis stream binder failed to start due to improper bean initialization

I am trying to run this simple kinesis message consumer with the following code. This is the only class in application
I am facing this error since, I have updated to latest snapshot version of kinesis binder
#SpringBootApplication
#RestController
#EnableBinding(Sink.class)
#EnableAutoConfiguration
public class ProducerApplication {
public static void main(String[] args) {
SpringApplication.run(ProducerApplication.class, args);
}
#StreamListener(Sink.INPUT)
public void listen(String message) {
System.out.println("Message has been received"+message);
}
}
Application yml
server.port: 8081
spring:
cloud:
stream:
bindings:
input:
destination: my.sink
content-type: application/json
cloud:
aws:
region:
static: us-east-1
credentials:
accessKey: <accessKey>
secretKey: <secretKey>
build.gradle
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
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: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.kinesis.demo'
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')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.cloud:spring-cloud-stream-binder-kinesis:1.0.0.BUILD-SNAPSHOT')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
I am getting the bean initialzation exception and there seems to be a problem in creating bean DynamoDbMetadataStore.
2018-07-10 10:53:22.629 INFO 18332 --- [esis-consumer-1] a.i.k.KinesisMessageDrivenChannelAdapter : Got an exception java.lang.IllegalStateException: The component has not been initialized: DynamoDbMetadataStore{table={SpringIntegrationMetadataStore: {AttributeDefinitions: [{AttributeName: KEY,AttributeType: S}],TableName: SpringIntegrationMetadataStore,KeySchema: [{AttributeName: KEY,KeyType: HASH}],TableStatus: ACTIVE,CreationDateTime: Wed Jun 27 10:51:53 IST 2018,ProvisionedThroughput: {NumberOfDecreasesToday: 0,ReadCapacityUnits: 1,WriteCapacityUnits: 1},TableSizeBytes: 0,ItemCount: 0,TableArn: arn:aws:dynamodb:us-east-1:1234567:table/SpringIntegrationMetadataStore,TableId: d0cf588b-e122-406b-ad82-06255dfea6d4,}}, createTableRetries=25, createTableDelay=1, readCapacity=1, writeCapacity=1, timeToLive=null}.
Is it declared as a bean? during [ShardConsumer{shardOffset=KinesisShardOffset{iteratorType=LATEST, sequenceNumber='null', timestamp=null, stream='my.sink', shard='shardId-000000000000', reset=false}, state=NEW}] task invocation.
Process will be retried on the next iteration.
This error started after updating to latest snapshot version of kinesis binder.
Can you please check if some thing is wrong.
I have just fixed the issue: https://github.com/spring-projects/spring-integration-aws/commit/fc34f814e557936d1bcb815d0879bd4f6e035675
The problem was that when we have already a table in the DynamoDB, we just return from the afterPropertiesSet() leaving the initialized as false.
The latest BUILD-SNAPSHOT should work now.

Gradle nebula.test fails to download Gradle distribution

I'm writing my first Gradle plugin. It's functionally working pretty well, and I have a couple of unit tests working. I'm now starting to set up integration tests using nebula.test. After resolving a simple Spock version number mismatch problem (I was loading 1.0, but nebula.test still uses 0.7) I'm now trying to run my first test. When I run it from Eclipse or from the command line, I see it fail with the following stacktrace:
org.gradle.api.GradleException: Build aborted because of an internal error.
at nebula.test.functional.internal.DefaultExecutionResult.rethrowFailure(DefaultExecutionResult.groovy:95)
at nebula.test.IntegrationSpec.runTasksSuccessfully(IntegrationSpec.groovy:234)
at com.att.opnfv.yang.gradle.YangPluginIntegSpec.simple(YangPluginIntegSpec.groovy:14)
Caused by: org.gradle.tooling.GradleConnectionException: Could not install Gradle distribution from 'https://services.gradle.org/distributions/gradle-2.3-bin.zip'.
at org.gradle.tooling.internal.consumer.DistributionFactory$ZippedDistribution$1.call(DistributionFactory.java:128)
at org.gradle.tooling.internal.consumer.DistributionFactory$ZippedDistribution$1.call(DistributionFactory.java:116)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
at org.gradle.tooling.internal.consumer.BlockingResultHandler.getResult(BlockingResultHandler.java:46)
at org.gradle.tooling.internal.consumer.DefaultBuildLauncher.run(DefaultBuildLauncher.java:71)
at nebula.test.functional.internal.toolingapi.BuildLauncherBackedGradleHandle.run(BuildLauncherBackedGradleHandle.groovy:78)
at nebula.test.IntegrationSpec.runTasks(IntegrationSpec.groovy:246)
at nebula.test.IntegrationSpec.runTasksSuccessfully(IntegrationSpec.groovy:232)
... 1 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:618)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:160)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:275)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:371)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
at org.gradle.wrapper.Download.download(Download.java:44)
at org.gradle.tooling.internal.consumer.DistributionFactory$ProgressReportingDownload.download(DistributionFactory.java:177)
at org.gradle.wrapper.Install$1.call(Install.java:59)
at org.gradle.wrapper.Install$1.call(Install.java:46)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:46)
at org.gradle.tooling.internal.consumer.DistributionFactory$ZippedDistribution$1.call(DistributionFactory.java:122)
at org.gradle.tooling.internal.consumer.DistributionFactory$ZippedDistribution$1.call(DistributionFactory.java:116)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
I imagine that most people will immediately suggest that I should configure my proxy. I'm pretty sure I've already done that. My Gradle build wouldn't work at all if I wasn't able to download artifacts from the internet. I put the relevant proxy config settings in my "~/.gradle/gradle.properties". I can also download this zip file in my browser, and I can also get it with "wget" from the same shell I ran the build from. The result from "wget" is interesting, however. When I run this, I see that it gets an intermediate "301 Moved Permanently" result, which points to "https://downloads.gradle.org/distributions/gradle-2.3-bin.zip".
Is there some part of this distribution download process that doesn't properly handle 301s, or do I have to configure that somehow?
Update:
Here's my build.gradle file:
buildscript {
repositories {
jcenter()
mavenCentral()
}
}
apply plugin: 'groovy'
apply plugin: 'java-gradle-plugin'
apply plugin: 'maven'
repositories {
mavenCentral()
jcenter()
maven { url "http://oss.sonatype.org/content/repositories/releases/" }
maven {
url "http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot"
}
maven {
url "http://nexus.opendaylight.org/content/repositories/opendaylight.release"
}
}
dependencies {
compile "org.codehaus.groovy:groovy-all:2.3.9"
compile gradleApi()
}
sourceCompatibility = 1.7
group = 'com.att.opnfv.yang'
version = '1.0.0-SNAPSHOT'
sourceSets {
integTest {
groovy.srcDir file("src/integTest/groovy")
resources.srcDir file("src/integTest/resources")
}
}
dependencies {
integTestCompile sourceSets.main.output
integTestCompile configurations.testCompile
integTestCompile sourceSets.test.output
integTestRuntime configurations.testRuntime
testCompile( 'com.netflix.nebula:nebula-test:2.2.0' ) {
exclude module: 'groovy-all'
}
}
task integTest(type: Test) {
testClassesDir = sourceSets.integTest.output.classesDir
classpath = sourceSets.integTest.runtimeClasspath
}
check.dependsOn -= integTest
And here's the first incomplete spec I'm trying to use with nebula test:
import nebula.test.IntegrationSpec
import nebula.test.functional.ExecutionResult
class YangPluginIntegSpec extends IntegrationSpec {
def 'simple'() {
writeHelloWorld("com.example")
buildFile << '''
applyPlugin('yang')
'''.stripIndent()
when:
ExecutionResult result = runTasksSuccessfully('build')
then:
println result
}
}

How to build Groovy JAR w/ Gradle and publish it to in-house repo

I have a Groovy project and am trying to build it with Gradle. First I want a package task that creates a JAR by compiling it against its dependencies. Then I need to generate a Maven POM for that JAR and publish the JAR/POM to an in-house Artifactory repo. The build.gradle:
apply plugin: "groovy"
apply plugin: "maven-publish"
repositories {
maven {
name "artifactory01"
url "http://myartifactory/artifactory/libs-release"
}
}
dependencies {
compile "long list starts here"
}
// Should compile up myapp-<version>.jar
jar {
}
// Should publish myapp-<version>.jar and its (generated) POM to our in-house Maven/Artifactory repo.
publishing {
publications {
myPublication(MavenPublication) {
from components.java
artifact sourceJar {
classifier "source"
}
pom.withXml {
// ???
}
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
However I do not believe I have set up versioning correctly with my jar task (for instance, how could I get it creating myapp-1.2.1 vs. myapp-1.2.2? I also don't think I have my publications configuration set up correctly: what should go in pom.withXml?
You're more than welcome to use artifactory plugin for that.
The documentation can be found in our user guide and below you can find a full working example of gradle build.
Run gradle build artifactoryPublish to build and publish the project.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1')
}
}
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
group = 'com.jfrog.example'
version = '1.2-SNAPSHOT'
status = 'SNAPSHOT'
dependencies {
compile 'org.slf4j:slf4j-api:1.7.5'
testCompile 'junit:junit:4.11'
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
publishing {
publications {
main(MavenPublication) {
from components.java
artifact sourcesJar
}
}
artifactory {
contextUrl = 'http://myartifactory/artifactory'
resolve {
repository {
repoKey = 'libs-release'
}
}
publish {
repository {
repoKey = 'libs-snapshot-local'
username = 'whatever'
password = 'whatever123'
}
defaults {
publications 'main'
}
}
}
package is a keyword in Java/Groovy, and you'd have to use a different syntax to declare a task with that name.
Anyway, the task declaration for package should be removed, as the jar task already serves that purpose. The jar task configuration (jar { from ... }) should be at the outermost level (not nested inside another task), but from configurations.compile is unlikely what you want, as that will include Jars of compile dependencies into the Jar (which regular Java class loaders can't deal with), rather than merging them into the Jar. (Are you even sure you need a fat Jar?)
Likewise, the publish task declaration should be removed, and replaced with publishing { publications { ... } }.
Also, the buildscript block should probably be removed, and repositories { ... } and dependencies { ... } moved to the outermost level. ( buildscript { dependencies { ... } } declares dependencies of the build script itself (e.g. Gradle plugins), not the dependencies of the code to be compiled/run.)
I suggest to check out the many self-contained example builds in the samples directory of the full Gradle distribution (gradle-all).

Resources