Can not publish Java project to Maven via BinTray with Gradle - java

I have a simple project I'm trying to publish to Maven via BinTray, but have been getting an error.
I have followed a guide to publish to bintray, and appear to have BinTray all set up, as well as access to Sonatype. Signing/etc, all appears to be good.
When I run "./gradlew bintrayUpload" I get an error, but the artifacts do show up on bintray. However I get various POM errors.
adams-MBP:UsedUtil adamhammer2$ ./gradlew clean install
:clean
:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.7
Note: /Users/adamhammer2/git/UsedUtil/src/main/java/com/mysaasa/usedutil/CallKeyGenerator.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 warning
:processResources UP-TO-DATE
:classes
:jar
:javadoc
:javadocJar
:sourcesJar
:install
BUILD SUCCESSFUL
Total time: 7.233 secs
adams-MBP:UsedUtil adamhammer2$ ./gradlew bintrayUpload
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:javadoc UP-TO-DATE
:javadocJar UP-TO-DATE
:sourcesJar UP-TO-DATE
:install
:bintrayUpload FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bintrayUpload'.
> Could not upload to 'https://api.bintray.com/content/adamhammer/maven/used-util/0.9.1/com/mysaasa/used_util/UsedUtil/0.9.1/UsedUtil-0.9.1.pom': HTTP/1.1 400 Bad Request [message:Unable to upload files: Maven group, artifact or version defined in the pom file do not match the file path 'com/mysaasa/used_util/UsedUtil/0.9.1/UsedUtil-0.9.1.pom']
* 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: 12.923 secs
Github project is https://github.com/ahammer/UsedUtil
build.gradle file is
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
}
apply plugin: 'java'
sourceCompatibility = 1.7
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
}
ext {
bintrayRepo = 'maven'
bintrayName = 'used-util'
publishedGroupId = 'com.mysaasa.used_util'
libraryName = 'UsedUtil'
artifact = 'usedutil'
libraryDescription = 'A Library for tracking usage in java projects'
siteUrl = 'http://ahammer.github.io/UsedUtil'
gitUrl = 'https://github.com/ahammer/UsedUtil.git'
libraryVersion = '0.9.1'
developerId = 'adamhammer'
developerName = 'Adam Hammer'
developerEmail = 'adamhammer2#gmail.com'
licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
After publishing I get the error, however in BinTray it registers the upload. When I click add to JCenter however I get another error "- Add a POM file to the latest version of your package."

Instead of using the 3rd party script and out of date plugin, I followed the guide
here https://github.com/bintray/gradle-bintray-plugin
This generated a proper pom file and published to bintray and made my package compatible with jcenter.
For a working build.gradle, you can look at my github for the working version.

Related

IntelliJ Main Error Migrating Projects: Exception in thread "Timer-0"

Overview
There is an issue when attempting to migrate a Kotlin AppEngine project from an old MacBook Pro (MBP) to a new MBP, when running the Main method and building a .jar file locally.
The Main method in IntelliJ fails intermittently on the new MBP. The old .jar runs as expected on the new MBP, and the new .jar runs as expected on the old MBP.
Expected
Run existing local .jar file from Kotlin project on the old MBP.
Clone Kotlin project from GitHub repository into local IntelliJ project on new MBP.
Build .jar on new MBP.
Run .jar on new MBP.
Host .jar on Google AppEngine instance.
Observed
Running .jar on existing MBP works as expected.
Running main method with the same code runs intermittently on the new MBP after the GitHub repo is cloned locally.
Error
The Main method runs on the old MBP as expected, but not on the new MBP with the following error.
Exception in thread "Timer-0" com.google.cloud.storage.StorageException: 401 Unauthorized
at com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:229)
at com.google.cloud.storage.spi.v1.HttpStorageRpc.create(HttpStorageRpc.java:310)
at com.google.cloud.storage.StorageImpl$3.call(StorageImpl.java:196)
at com.google.cloud.storage.StorageImpl$3.call(StorageImpl.java:193)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105)
at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
at com.google.cloud.storage.StorageImpl.internalCreate(StorageImpl.java:192)
at com.google.cloud.storage.StorageImpl.create(StorageImpl.java:154)
at content.SaveContentKt.saveContent(SaveContent.kt:38)
at content.ContentTasks.generateContent(ContentTasks.kt:55)
at content.ContentTasks.run(ContentTasks.kt:41)
at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
at java.base/java.util.TimerThread.run(Timer.java:506)
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:150)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:554)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:474)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:591)
at com.google.cloud.storage.spi.v1.HttpStorageRpc.create(HttpStorageRpc.java:307)
... 12 more
Configuration
The gradle-wrapper.properties Gradle, IntelliJ Preferences Gradle JVM, Project SDK, Run/Debug Configurations JRE, and Project language level versions are the same across both machines.
Preferences > Gradle
Use Gradle from: 'gradle-wrapper.properties' file
Gradle JVM: Library/Java/JavaVirtualMachines/12.0.1
File > Project Structure... > Project
Project SDK: 12.0.1
Project language level: 11
Running .jar file: Project Structure > Project Settings > Artifacts > Add > JAR > From modules with dependencies...
Module: coinverse-media.main
Main Class: Initialization
Lastly, build artifact and run .jar file.
build.gradle
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.2.51'
}
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation 'com.squareup.retrofit2:retrofit:2.7.0'
implementation 'com.squareup.retrofit2:converter-gson:2.7.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.7.0'
implementation 'com.google.firebase:firebase-admin:6.12.0'
implementation 'com.google.cloud:google-cloud-storage:1.102.0'
implementation 'com.google.apis:google-api-services-youtube:v3-rev20190827-1.30.1'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
Attempted Solutions
Invalidate Caches / Restart...: This appears to fix the issue for a few times running the Main method, then the error continues to show.
./gradlew clean build
Gradle > Reimport All Gradle Projects
Updating to the latest Gradle version.
Ensure existing MBP and new MBP are running on the same IntelliJ/Project/Run configurations.
Potentially related build dependency conflict issue: Guava Dependency Breaking Jar Built With Kotlin.
Build Data
Build scan results
Stack trace
6:09:42 PM: Executing task 'assemble'...
Task :compileKotlin UP-TO-DATE
Task :compileJava NO-SOURCE
Task :processResources NO-SOURCE
Task :classes UP-TO-DATE
Task :inspectClassesForKotlinIC UP-TO-DATE
Task :jar UP-TO-DATE
Task :assemble UP-TO-DATE
BUILD SUCCESSFUL in 75ms
3 actionable tasks: 3 up-to-date
6:09:42 PM: Task execution finished 'assemble'.
Hidden files

Is it mandatory to define the java plugin to download the depdendency in gradle script?

I am writing the gradle script where I need to download the multiple jar files from artifactory I am using the apply plugin 'java' in gradle script and able to fetch those jar files from artifactory easily but if I apply this plugin it run the jar task automatically and creates the jar which I don't want.Is there a way to download the jar files from artifactory with/without using the java plugin so that jar task couldn't trigger.
apply plugin 'java'
apply plugin: 'base'
//-- set the group for publishing
group = 'com.abcdef.covery'
/**
* Initializing GAVC settings
*/
def buildProperties = new Properties()
file("version.properties").withInputStream {
stream -> buildProperties.load(stream)
}
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.coveryadBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.scoveryadBuildVersion
println "${version}"
//name is set in the settings.gradle file
group = "com.abcdef.discovery"
version = buildProperties.coveryadBuildVersion
println "Building ${project.group}:${project.name}"
repositories {
maven {
url "http://art.tsh.tho.com:90000/artifactory/services"
}
}
dependencies {
runtime "covery.services:AddService:1.0#jar"
runtime "covery.services:AddService:1.1#jar"
runtime "covery.services:Services:1.0#jar"
runtime "covery.services:Services:1.1#jar"
}
task copyDeps(type: Copy) {
from configurations.runtime
into 'services/discovery/services/'
}
output:Below shows few tasks which are running while using the java plugin in the script and if I don't use then it doesn't download the jar files from artifactory.
16:28:32 Building com.abcdefgh.discovery:cdad
16:28:33 [buildinfo] Properties file found at 'C:\Windows\TEMP\buildInfo429617857022686528.properties'
16:28:35 :copyDeps UP-TO-DATE
16:28:36 :deletebuild
16:28:37 :buildreportZip
16:28:38 :deleteGraphicsAssets
16:28:47 :unzip
16:28:47 :compileJava UP-TO-DATE
16:28:47 :processResources UP-TO-DATE
16:28:47 :classes UP-TO-DATE
16:28:47 :jar
16:28:47 :artifactoryPublish
16:28:47 Deploying artifact: http://localhost:8081/artifactory/libs-release-local/com/abcdefg/covery/cdad/03_00_00_183/cdad-03_00_00_183.zip
16:28:53 Deploying artifact: http://localhost:8081/artifactory/libs-release-local/com/abcdefl/covery/cdad/03_00_00_183/cdad-03_00_00_183.jar
You do not need to add the java plugin to download dependencies. If you do not have any java source files I would recommend that you use the baseplugin instead:
apply plugin: 'base'
repositories {
mavenCentral()
}
configurations {
nameOfMyConfiguration
}
dependencies {
nameOfMyConfiguration 'org.scala-lang:scala-library:2.10.4'
}
task zipMyStuff(type: Zip) {
from configurations.nameOfMyConfiguration
}

IntelliJ 14 Java project not aware of Gradle dependancy

I have an IntelliJ idea project which has a number of dependencies in build.gradle.
However just recently after adding dependencies to buid.gradle, IntelliJ doesn't seem to be aware of them (despite Gradle building and running the applicaition fine).
My build.gradle:
apply plugin: 'java'
version = '1.0'
repositories {
mavenLocal()
maven { url * } // Company's proxy maven repository
}
dependencies {
compile("wsdl4j:wsdl4j:1.6.2")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.0-milestone-4'
distributionUrl = * // Company gradle distrubution URL
}
apply plugin: 'application'
mainClassName = "main.HelloWorld"
But when I use a class that is dependant, for example: javax.wsdl.xml.WSDLReader, IntelliJ looks like this
Despite it compiling and running fine.
:clean
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
:run
Hello, World
BUILD SUCCESSFUL
How do I make IntelliJ aware of the classes?
I managed to fix this myself:
Under the toolbar I went View->Toolbars->Gradle. Then a sub window opened on the right. I then clicked on the refresh button, shown here:
And after a few moments is was all good!

Getting NoClassDefFoundError while running PMD task from Gradle

I am getting NoClassDefFoundError while running PMD task via Gradle.
I am having pmd-5.1.1.jar, commons-io-1.4.jar as well as all the other jars in WebContent/WEB-INF/lib directory. My java files are in the directory src\com\company\project
Gradle Build file
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'pmd'
sourceSets.main.java.srcDirs = ['src']
webAppDirName = 'WebContent'
repositories {
flatDir { dirs "WebContent/WEB-INF/lib" }
}
dependencies {
providedCompile fileTree(dir: "WebContent/WEB-INF/lib", include: '*.jar')
}
war {
archiveName "ROOT.war"
}
Error Log
C:\MyWorkspace\MyProject>gradle build
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:war UP-TO-DATE
:assemble UP-TO-DATE
:pmdMain FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':pmdMain'.
> java.lang.NoClassDefFoundError: org/apache/commons/io/IOUtils
* 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: 5.275 secs
This is the first time I am trying Gradle. I am able to build as well as generate WAR but PMD is failing me. Can someone please tell me what am I doing wrong? Thanks in advance :)
I know that You've already found the answer but FYI I'm adding solution to the problem.
Basically You have non standard project structure. First of all, web content should be placed under src/main/webapp (sources under src/main/java and so on). Secondly You should not put diagnostics tools (pmd) under WEB-INF/lib. There's no need to have this jars deployed along with the whole application to the application server.
There was also no declaration of maven repo, so the dependencies could not be resolved (commons-io, asm, jaxen, etc.) and the were missing dependencies under pmd classpath (commons-io, etc.) - note the pmd scope in dependencies block.
Here you can find two projects - with standard and non-standard project layout. Both are configured correctly.
At last found the issue. I needed to resolve pmd and all it's transitive dependencies from a remote repo like Maven Central.
repositories {
mavenCentral()
}
pmd {
toolVersion = "5.1.1"
ignoreFailures = true
}

Followup to Gradle 1.3: build.gradle not building classes

I am actually using the newly released Gradle 2, but having the same issues as described in the previous post.
I am also a newb trying to follow the example given in the Spring guide (http://spring.io/guides/gs/gradle/#scratch) but after my first compile, there were no classes.
I have tried various configurations of tree structure including adding the structure and code suggested in the above thread:
"I guess the source file path is src/org/gradle/example/simple/HelloWorld.java. (The diagram shows something different.) That doesn't match Gradle's default, so you'll have to reconfigure it: sourceSets.main.java.srcDirs = ["src"] – Peter Niederwieser Dec 7 '12 at 1:23 "
adding the line: sourceSets.main.java.srcDirs = ["src"] allows the code to compile, however, I still have no classes.
Here is the successful build.
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE
BUILD SUCCESSFUL
Total time: 4.468 secs
Here is the build file:
apply plugin: 'java'
sourceSets.main.java.srcDirs=["src"]
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile "joda-time:joda-time:2.2"
}
jar {
baseName = 'gs-gradle'
version = '0.1.0'
}
task wrapper(type:Wrapper) {
gradleVersion = '1.11'
}
apply plugin: 'application'
mainClassName = 'hello.HelloWorld'
Where are my classes? Please help.
After I got stuck with the same problem, I hacked around for a bit before I understood the reason for this behavior.
My project structure was like so
MyProject
- src
- main
- java
- hello
HelloWorld.java
build.gradle
The problem was that the build.gradle is supposed to be under the Project-Root folder i.e. MyProject and not under the hello folder !!!
Changed it so that my Project structure looks like below, ran the gradle build and saw that classes folder was created:
MyProject
- src
- main
- java
- hello
HelloWorld.java
build.gradle
When you think about it, the build.gradle is used to build the complete project and not just the classes within one folder and should rightfully sit under the project-root folder.

Categories

Resources