I am trying to publish a Java library to maven central repository.
I have never done this before. This project is for testing purposes. When I figure out
how to properly publish a project, I will then publish an actual library.
My goal is to be able to add this project as a dependency for other projects.
I know I could include it as a .jar, but I want to learn about other ways of importing dependencies.
While running the task:
./gradlew publish
in my project root folder, I get the build error:
> Task :signMavenJavaPublication FAILED
Caching disabled for task ':signMavenJavaPublication' because:
Build cache is disabled
Task ':signMavenJavaPublication' is not up-to-date because:
Task has failed previously.
:signMavenJavaPublication (Thread[Execution worker for ':',5,main]) completed. Took 0.004 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':signMavenJavaPublication'.
> Cannot perform signing task ':signMavenJavaPublication' because it has no configured signatory
EDIT:
I have made some progress. I will post this at the bottom of the question.
For the past four days, I have been trying to figure out why. I will post the build code further below, but first I will go through all the steps I followed to be able to publish to the central repository in the first place.
My gradle experience is limited, but I think I know the basics.
I have read various documentation on:
central.sonatype.org
Gradle
for how to publish / sign. I don't know exactly what i am doing or why.
Apply for a GroupID on Sonatype Jira. This issue/ticket is resolved. And I should be able to publish SNAPSHOT and release artifacts to s01.oss.sonatype.org. My GroupID is my github domain. So, as far as I know, this lets me publish my projects / libraries under "io.github.username".
Download and set up GnuPG:
At some point in the set up I was asked to create a GnuPG password (signing.password).
Don't remember when.
gpg --gen-key
Entering my name and email. Now I can type:
gpg -K
And I get the following (not actual values):
sec ed25519 2022-05-25 [SC] [expires: 2024-05-24]
****************************************
uid [ultimate] My Name <my-email#mail.com>
ssb cv25519 2022-05-25 [E] [expires: 2024-05-24]
So, the **************************************** is the password I am using. (the final 8 digits).
Now I export the key.(I think it creates my secret key right?):
gpg --export-secret-keys ******** > C:\users\username\secring.gpg
As far as I know, this could be any folder. As long as the folder corresponds to the:
signing.secretKeyRingFile=\users\username\secring.gpg
in the gradle.properties file.
Also, what would be the correct way to type this?
signing.secretKeyRingFile=\users\username\secring.gpg
signing.secretKeyRingFile=C:\users\username\secring.gpg
signing.secretKeyRingFile=C:\\users\\username\\secring.gpg
signing.secretKeyRingFile="C:\\users\\username\\secring.gpg"
(I think I have tried all the variations)
Then I need to send the public key to some key server. And there are some alternatives:
keyserver.ubuntu.com
keys.openpgp.org
pgp.mit.edu
I have tried to send it to all of them.
gpg --keyserver hkp://keyserver.ubuntu.com --send-keys ****************************************
And to can check if the server received the key:
gpg --keyserver hkp://keyserver.ubuntu.com --search-key 'my-email#mail.com'
And they got it. At least the server responds with the last 16 or so digits of the key.
So at this point I set up a simple java test project named "Storage". Pushing it to my github repo. under the same name.
And now we can get to the gradle files. Keep in mind, I'm not entirely sure if this is correct. If I left out something, or something is unnecessary. Please let me know.
build.gradle
plugins {
id 'java-library'
id 'signing'
id 'maven-publish'
}
group 'io.github.username'
version '0.0.1'
repositories {
mavenCentral()
maven { url "http://repo.maven.apache.org/maven2" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {}
java {
withJavadocJar()
withSourcesJar()
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'io.github.username'
artifactId = 'storage'
version = '0.0.1'
from components.java
pom {
name = 'Storage'
description = 'Storage is an open-source Java library test'
url = 'https://github.com/username/Storage'
inceptionYear = '2022'
licenses {
license {
name = 'MIT License'
url = 'http://www.opensource.org/licenses/mit-license.php'
}
}
developers {
developer {
id = 'sonatype-username'
name = 'Full Name'
email = 'my-email#mail.com'
}
}
scm {
connection = 'scm:git:git://github.com/username/Storage.git'
developerConnection = 'scm:git:ssh://github.com/username/Storage.git'
url = 'https://github.com/username/Storage'
}
}
}
}
repositories {
maven {
name = "OSSRH"
url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username = project.properties["ossrhUsername"]
password = project.properties["ossrhPassword"]
}
}
}
}
signing {
sign publishing.publications.mavenJava
}
javadoc {
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}
gradle-wrapper.properties
# auto-generated
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
# Sonatype variables
ossrhUsername=username
ossrhPassword=password
# GnuPG
signing.keyId=********
singing.password=GnpPassword
signing.secretKeyRingFile=\Users\username\secring.gpg
settings.gradle
rootProject.name = 'Storage'
That should be it. But I can include versions of various software/tools:
OS Windows 10
GnuPG 2.3.6
Gradle 7.4.2
Java 13.0.1
Groovy 3.0.9
PROGRESS:
I got the project published to Nexus repository manager.
So I know for a fact that build.gradle can access my gradle.properties file and can read it's content.
I got the publish task to work by excluding the signing part.
I have sent my key (two keys now) to both:
keyserver.ubuntu.com
pgp.mit.edu
keys.openpgp.org does not seem to work. I get gpg: keyserver send failed: Certificate expired
When i send a key to a server I use the FULL KEY ID.
I can query a server to see if they in fact received the keys: gpg --keyserver hkp://keyserver.ubuntu.com --search-key 'my-email#mail.com'
And both servers have received 2 keys:
(1) My Name <my-email#mail.com>
263 bit EDDSA key ****************, created: 2022-05-28
(2) My Name <my-email#mail.com>
263 bit EDDSA key ****************, created: 2022-05-25
Keys 1-2 of 2 for "my-email#mail.com". Enter number(s), N)ext, or Q)uit >
The **************** is in fact the last numerals of my keys. It has to be right. Should I only send the last 8 numerals of the key to a server?
And the singing.password I use is the same choose when creating a key.
But for some esoteric reason. The signing still does not work. Is there no way to pinpoint the EXACT reason for failure?
Please, take a look at my build.gradle. Is there an alternative way to publishing / signing i could try instead?
Does the name of the secret key file matter? secring.gpg
The error piece:
> Cannot perform signing task ':signMavenJavaPublication' because it has no configured signatory
basically says that your signing task is not able to figure out the signature info it needs to execute. Most likely it cannot find your gradle-wrapper.properties file.
What you can do is to try to put them in the main gradle.properties file and see how it goes.
As for the folders: Gradle relies on java.io.File for its path related operations which means it should be able to handle forward slashes as well.
A good approach, especially when you are setting up a new configuration and you see it failing for path reasons, is to put everything straight into the folder where you're sure Gradle (or any other system/build) is able to see it. In your case that would be either gradle home or same folder where your build.gradle is. Then, after you get everything to work, you can reorganize and put configs however you like.
EDIT:
It is also always a good idea to find a way how to printout something while your build / script / whatever is executing. So, for Gradle you can use println to print a property name:
task printSigning {
println(project.findProperty('signing').secretKeyRingFile)
}
Or you can print a current directory:
task currentDir {
println file('.')
}
I hope that this helps a bit.
Below questions might contain some more details and give you a hint too:
https://stackoverflow.com/a/67115705/177154
https://stackoverflow.com/a/68505768/177154
The application which I am working on is debugging fine in emulator or in mobiles but when I try to build the apk it gives the following Error:
Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety
Running Gradle task 'assembleRelease'...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lintVitalRelease'.
> Could not resolve all artifacts for configuration ':image_picker_android:debugUnitTestRuntimeClasspath'.
> Failed to transform bcprov-jdk15on-1.68.jar (org.bouncycastle:bcprov-jdk15on:1.68) to match attributes {artifactType=processed-jar, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
> Execution failed for JetifyTransform: /home/cicada/.gradle/caches/modules-2/files-2.1/org.bouncycastle/bcprov-jdk15on/1.68/46a080368d38b428d237a59458f9bc915222894d/bcprov-jdk15on-1.68.jar.
> Failed to transform '/home/cicada/.gradle/caches/modules-2/files-2.1/org.bouncycastle/bcprov-jdk15on/1.68/46a080368d38b428d237a59458f9bc915222894d/bcprov-jdk15on-1.68.jar' using Jetifier. Reason: IllegalArgumentException, message: Unsupported class file major version 59. (Run with --stacktrace for more details.)
Suggestions:
- Check out existing issues at https://issuetracker.google.com/issues?q=componentid:460323&s=modified_time:desc, it's possible that this issue has already been filed there.
- If this issue has not been filed, please report it at https://issuetracker.google.com/issues/new?component=460323 (run with --stacktrace and provide a stack trace if possible).
* 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 19s
Running Gradle task 'assembleRelease'... 20.7s
Gradle task assembleRelease failed with exit code 1
Process finished with exit code 1
This was my solution which I recommend to be the 2nd option:
Solution 1:
I added following lines in the android directory of app level build.gradle i.e android/app/build.gradle of my project.
lintOptions {
disable 'InvalidPackage'
disable "Instantiatable"
checkReleaseBuilds false
abortOnError false
}
And every thing started to work fine.
Check out my Gradle File
Solution 2:
However I suggest you people by the solution of #Vinadon and agree with the comment of #raiderOne:
1st recommended solution should be:
The issues lies in image_picker_android being updated to gradle 7.1.2. See their changelog. Following an issue on GitHub you have to update your gradle version like so:
In android/gradle/wrapper/gradle-wrapper.properties update your distributionUrl to
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
and in android/build.gradle change the gradle version to at least 7.1.2
classpath 'com.android.tools.build:gradle:7.1.2
In #Vinadon case, He had to update his Android Studio for a newer Java version too.
Upvote Vindadon answer below for this solution. Thanks!
The issues lies in image_picker_android being updated to gradle 7.1.2. See their changelog. Following an issue on GitHub you have to update your gradle version like so:
In android/gradle/wrapper/gradle-wrapper.properties update your distributionUrl to
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
and in android/build.gradle change the gradle version to at least 7.1.2
classpath 'com.android.tools.build:gradle:7.1.2
In my case, I had to update my Android Studio for a newer Java version too.
Let me help you a little bit in finding the correct place to paste the code
1: Go to your app-level build.grade.
2:Scroll down to "android{ "
paste this code carefully(not disturbing any other brakets.)
lintOptions {
disable 'InvalidPackage'
disable "Instantiatable"
checkReleaseBuilds false
abortOnError false
}
3:run "flutter clean"
4:run "flutter pub get"
5:If you want to build apk of your project then run "flutter build apk"
I hope it works for you.
The solution is actual on 06.06.2022. Adding these lines in pubspec.yaml fixed the problem:
dependency_overrides:
image_picker_android: 0.8.4+13
if you are using flutter 3.0 and image_picker, try this:
dependency_overrides:
image_picker_android: 0.8.4+13
This issue is usually because the gradle plugin is outdated. If your project was created using an older version of flutter the gradle plugin will be old. The actual fix to this issue would be to upgrade the gradle plugin version.
Refer to this issue
You can use android studio to do this for you or just edit the files on your own.
if you are using flutter 3.3 and image_picker, try this:
dependency_overrides:
image_picker_android: 0.8.5+3
I had the same issue, I fixed that by adding the line android.jetifier.blacklist=org.robolectric.*,bcprov in gradle.properties
This is the error message I got,
I have this error in eclipse helios:
Exception occurred executing command line.
Cannot run program "C:\Program Files (x86)\Java\jre6\bin\javaw.exe" (in directory "C:\Users\motiver\helios_workspace\TimeTracker"): CreateProcess error=206, The filename or extension is too long
I researched a bit but most of the issues were related to DataNucleus when working on Google App Engine. But I am not using anything remotely related to Google App Engine. I am doing a small project with Servlet 3.0 on JBOSS 6. I am using Hibernate 4.1.2 for ORM and RESTEasy to expose a web service. I created a util file that has a main() method that basically drops and re-creates the schema. I run the main() methos when I need a clean database for testing purposes. It worked fine on Tomcat 7 but it stopped working when I moved to JBoss 6.
Any hint or solution would be greatly appreciated.
There is no simple (as in a couple of clicks or a simple command) solution to this issue.
Quoting from some answers in this bug report in Eclipse.org, these are the work-arounds. Pick the one that's the least painful to you:
Reduce the classpath
Use directories instead of jar files
Use a packed jar files which contains all other jars, use the classpath variable inside the manifest file to point to the other jars
Use a special class loader which reads the classpath from a config file
Try to use one of the attached patches in the bug report document
Use an own wrapper e.g. ant
Update: After July 2014, there is a better way (thanks to #Brad-Mace's answer below:
If you have created your own build file instead of using Project -> Generate Javadocs, then you can add useexternalfile="yes" to the Javadoc task, which is designed specifically to solve this problem.
In intellij there is an option to 'shorten command line', select 'JAR manifest' or '#argFiles' would solve the problem, basically it will put your lengthy class path into a jar file or a temp file
I faced this problem today and I was able to solve it using this Gradle plugin
It's github url is this
IF you, like me, have no idea what Gradle is but need to run a backend to do your front end work, what you need to do is find the build.gradle file that is being called to start your BE server and add this to the top:
plugins {
id "ua.eshepelyuk.ManifestClasspath" version "1.0.0"
}
If you create your own build file rather than using Project -> Generate Javadocs you can add useexternalfile="yes" to the javadoc task, which is designed specifically to solve this problem.
I was running into this issue trying to execute a JPQL query in the Hibernate / JPA console of IntelliJ 2020.2
Adding this to my .idea/workspace.xml fixed it
<component name="PropertiesComponent">
...
<property name="dynamic.classpath" value="true"/>
...
</component>
Origin of the solution: https://youtrack.jetbrains.com/issue/IDEA-166929?_ga=2.167622078.1290412178.1604511702-23036228.1574844686
Answering my own question here so that the solution doesn't get buried in comments. I exported the project as a runnable jar from within eclipse and did a command line "java -jar MyJar.jar" and it works perfectly fine
This is not specifically for eclipse, but the way I got around this was by creating a symbolic link to my maven repository and pointing it to something like "C:\R". Then I added the following to my settings.xml file:
<localRepository>C:\R</localRepository>
The maven repository path was contributing to the length problems in my windows machine.
Try updating your Eclipse version, the issue was closed recently (2013-03-12). Check the bug report https://bugs.eclipse.org/bugs/show_bug.cgi?id=327193
Question is old, but still valid. I come across this situation often whenever a new member joins my team or a new code segment is added to existing code. Simple workaround we follow is to "Reduce the classpath" by moving up the directories.
As question mentioned, this is not specific to eclipse. I came across this issue in IntelliJ Idea 14 and 2018 as well.
After a long research, I found the solution is to set the
fork = false
in javc of ant build file.
<javac destdir="${build.dir}" fork="false" debug="on">
<classpath .../>
<src ... />
<patternset ... />
</javac>
This is how my ant build javac looks now. To learn about more on fork, please refer ant documentation.
In bug report Bug 327193 it is considered fixed, but it happen to me recently with Eclipse Kepler 4.3.2.
Please download patch for Eclipse Juno or newer:
https://bugs.eclipse.org/bugs/attachment.cgi?id=216593
After download back up existing
eclipse/plugins/org.eclipse.jdt.launching_3.*.jar
Copy and paste classes in the patch to org.eclipse.jdt.launching JAR
(replace existing files).
Restart Eclipse.
How many people sad above, there are a lot of plugins to gradle execute a by pass in this problem like:
plugins {
id "ua.eshepelyuk.ManifestClasspath" version "1.0.0"
}
or
plugins {
id "com.github.ManifestClasspath" version "0.1.0-RELEASE"
}
But the better solution that I found was kill the JVM process and everything is done.
Add below to your gradle file:
plugins {
`id "com.github.ManifestClasspath" version "0.1.0-RELEASE"
}
See https://plugins.gradle.org/plugin/com.github.ManifestClasspath
Try adding this in build.gradle (gradle version 4.10.x) file and check it out com.xxx.MainClass this is the class where your main method resides:
plugins {
id "ua.eshepelyuk.ManifestClasspath" version "1.0.0"
}
apply plugin: 'application'
application {
mainClassName = "com.xxx.MainClass"
}
The above change must resolve the issue, there is another way using script run.sh below could fix this issue, but it will be more of command-line fix, not in IntelliJ to launch gradle bootRun.
Try this:
java -jar -Dserver.port=8080 build/libs/APP_NAME_HERE.jar
To solve it:
If you are using Eclipse:
Move .m2 repository to
c:\
Go to Eclipse > Windows/Preferences/Maven/User Settings -> Create your own setting.xml with its content:
<settings>
<localRepository>c:/.m2/repository</localRepository>
</settings>
If you are using IntelliJ:
Go to IntelliJ > clicking the right mouse button on "pom.xml" > maven > create "settings.xml"
with its content:
<settings>
xmlns="yourcontent"
xmlns:xsi="yourcontent"
xsi:schemaLocation="yourcontent.xsd">
<localRepository>c:/.m2/repository</localRepository>
</settings>
In my case the error was showing because system java version was different from intellijj/eclipse java version. System and user had diff java versions. If you compile your code using one version and tried to run using a different version, it will error out.
#The system java version is 1.7.131
$ java -version
java version "1.7.0_131"
Long story short, make sure your code is compiled and ran by the same java version.
I am using legacy version of gradle plugins and this plugin solved the issue for me.
Usage (check source for more details):
Build script snippet for plugins DSL for Gradle 2.1 and later
plugins {
id "com.github.ManifestClasspath" version "0.1.0-RELEASE"
}
Build script snippet for use in older Gradle versions or where dynamic
configuration is required
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.github.viswaramamoorthy:gradle-util-plugins:0.1.0-RELEASE"
}
}
apply plugin: "com.github.ManifestClasspath"
I have got same error, while invoking Maven.
The root cause for my problem was the classpath was very huge. Updating the classpath fixed the problem.
There are multiple ways to update the large classpath as mentioned in this: How to set a long Java classpath in Windows?
Use wildcards
Argument File
Pathing jar
Since I am using Intellij, they provide the option to use Argument File that i used.
In a Windows machine, there is a limitation of the jar file name/path length in the command-line, due to which you see the below error message, I tried searching a lot, even I tried applying the above solution, some reason, it didn't work, I found the working snippet for Gradle (gradle-4.10.2-all.zip)
Error:
CreateProcess error=206, The filename or extension is too long
Use this below gradle.build code snippet to fix the above problem in IntelliJ or STS, or eclipse anything.
Gradle Code Fix:
apply plugin: 'application'
task pathingJar(type: Jar) {
dependsOn configurations.runtime
appendix = 'pathing'
doFirst {
manifest {
attributes "Class-Path": configurations.runtimeClasspath.files.collect { it.getName() }.join(' ')
}
}
}
task copyToLib(type: Copy) {
into "$buildDir/libs"
from configurations.runtime
}
bootRun {
systemProperties = System.properties
//This below line is for if you have different profiles prod, dev etc...
//systemProperty 'spring.profiles.active', 'dev'
jvmArgs('-Djava.util.logging.config.file=none')
mainClassName = "com.xxxx.Main"
dependsOn pathingJar
dependsOn copyToLib
doFirst {
classpath = files("$buildDir/classes/java/main", "$buildDir/resources/main", pathingJar.archivePath)
}
}
If you are using VSCode:
create launch.json file insde .vscode/
add
{"configurations": [{ "type": "java","shortenCommandLine ": "auto",}]}
If you are using intellij :
open .idea/workspace.xml
inside <component name="PropertiesComponent">
add <property name="dynamic.classpath" value="true"/>
it happens due to DataNucleus sometimes overwrite the Arguments with many paths.
You have to overwrite them with this:
-enhancerName ASM -api JDO -pu MediaToGo
Hope help you!
I got the same error. Tried solutions like cleaning, rebuild, invalidateCache, retart etc but nothing works.
I just have created a new folder with short name and copied all the files(app folder, gradle files etc) in new folder. Opened application in android studio and its working fine.
For me it was wrong JDK path. Please make sure you have right path to the JDK file
File -> Project Structure
If you are using Android Studio try Invalidate Caches/ Restart.. option present in File menu
I used com.virgo47.ClasspathJar plugin to fix this issue
https://plugins.gradle.org/plugin/com.virgo47.ClasspathJar
To fix this below error, I did enough research, not got any great solution, I prepared this script and it is working fine, thought to share to the public and make use of it and save there time.
CreateProcess error=206, The filename or extension is too long
If you are using the Gradle build tool, and the executable file is placed in build/libs directory of your application.
run.sh -> create this file in the root directory of your project, and copy below script in it, then go to git bash and type run.sh then enter. Hope this helps!
#!/bin/bash
dir_name=`pwd`
if [ $# == 1 ] && [ $1 == "debug" ]
then
port=$RANDOM
quit=0
echo "Finding free port for debugging"
while [ "$quit" -ne 1 ]; do
netstat -anp | grep $port >> /dev/null
if [ $? -gt 0 ]; then
quit=1
else
port=`expr $port + 1`
fi
done
echo "Starting in Debug Mode on "$port
gradle clean bootjar
jar_name="build/libs/"`ls -l ./build/libs/|grep jar|grep -v grep|awk '{print $NF}'`
#java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$port $jar_name
elif [ $# == 1 ] && [ $1 == 'help' ]
then
echo "please use this commands"
echo "------------------------"
echo "Start in Debug Mode: sh run.sh debug"
echo "Start in Run Mode: sh run.sh"
echo "------------------------"
else
gradle clean bootjar
word_count=`ls -l ./build/libs/|grep jar|grep -v grep|wc -w`
jar_name=`ls -l ./build/libs/|grep jar|grep -v grep|awk '{print $NF}'`
jar_path=build/libs/$jar_name
echo $jar_name
#java -jar $jar_path
fi
Hope this helps!!
You can use below commands:
mklink /J c:\repo C:\<long path to your maven repository>
mvn -Dmaven.repo.local=c:\repo any mvn command
Valid answer from this thread was the right answer for my special case.
Specify the ORM folder path for datanucleus certainly reduce the java path compile.
https://stackoverflow.com/a/1219427/1469481
I got the error below when I run 'ant deploy'
Cannot run program "C:\java\jdk1.8.0_45\bin\java.exe": CreateProcess error=206, The filename or extension is too long
Fixed it by run 'ant clean' before it.
I got the same error in android studio. I was able to resolve it by running Build->Clean Project in the IDE.