Gradle: publish existing jar/source/javadoc to maven - java

I have some proprietary libraries which are used in my java project. I use gradle as build manager. I use the eclipse-ide.
Since I dont want to have any binaries in my repo, I created a custom maven repository. Prior to Gradle 6.x Gradle just downloaded the .jar file with the correct folder structure in the repository (GROUPNAME/ARTIFACT/VERSION/... .jar)
After I updated to Gradle 6.5 Gradle wanted a .pom file to specify the jar. So I created a dummy project with this build file and used the command gradle install to get the .pom file.
plugins {
id 'java-library'
id 'maven'
}
repositories {
jcenter()
}
dependencies {
api group: 'commons-codec', name: 'commons-codec', version: '1.10'
api group: 'commons-logging', name: 'commons-logging', version: '1.2'
api group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
api group: 'log4j', name: 'log4j', version: '1.2.17'
}
install {
repositories.mavenInstaller {
pom.version = '...'
pom.groupId = '...'
pom.artifactId = '...'
}
}
With this method I had to rename the library jar accordingly. Now I have the .pom file but missing all the md5/sha/metafile/... files which are normaly generated with the maven-publish plugin.
I either need to know how to configure my dummy project to generate the md5/sha/metafile/... without having the source code - just have the .jar/sources.jar/javadoc.jar
OR I need to know how to configure my normal build to download the javadoc/sources withouth the correct .pom file

Related

Gradle to use a jar-with-dependencies in compile task

We have a project that make use of 'jrs-rest-java-client', version: '6.3.1'
The site we used to get the jar from has a certificate issue since September. https://jaspersoft.artifactoryonline.com
We then had to get the jar from a different site.
https://jaspersoft.jfrog.io/
The problem is that a dependency require is missing, but if we use the jar that has "-jar-with-dependencies" it is working. I tried by downloading that jar locally and changing the .gradle to use the local version.
What I would prefer is to have the build to fetch that version directly without having to download first.
How do we specify what jar to use?
dependencies {
compile fileTree(dir: 'lib',
includes: [
'ojdbc8.jar',
])
//compile group: 'com.jaspersoft', name: 'jrs-rest-java-client', version: '6.3.1'
compile group: 'com.jaspersoft', name: 'jrs-rest-java-client', version: '6.3.1', USETHISONE: 'jar-with-dependencies'
//compile files("${buildDir}/jrs-rest-java-client-6.3.1-jar-with-dependencies.jar")
}
I have now tried as suggested;
repositories {
mavenCentral()
// to handle broked jasper reports dependencies
maven {
url 'http://jasperreports.sourceforge.net/maven2'
url 'https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/'
url "https://jaspersoft.jfrog.io/jaspersoft/jaspersoft-clients-releases"
}
}
dependencies {
implementation project(':common:project-common-properties')
implementation project(':common:project-common-mail')
implementation fileTree(dir: 'lib', includes: [
'ojdbc8.jar'
])
implementation group: 'com.jaspersoft', name: 'jrs-rest-java-client', version: '6.3.1', classifier: 'jar-with-dependencies'
}
I'm still getting errors at build time...
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':services:notificationService:compileClasspath'.
> Could not find com.jaspersoft.jasperserver:jasperserver-dto:6.3.0.
Required by:
project :services:notificationService > com.jaspersoft:jrs-rest-java-client:6.3.1
That library is not required if the jrs-rest-java-client-6.3.1-jar-with-dependencies.jar is used.
Thanks all,
The solution was, as seen if the video (Thanks!)
adding a new url:
url "https://jaspersoft.jfrog.io/jaspersoft/jrs-ce-releases"
From the jfrog repo, it shows you how to do this:
compile(group: 'com.jaspersoft', name: 'jrs-rest-java-client', version: '6.3.1', classifier: 'jar-with-dependencies')
Add the repo for gradle:
repositories {
jcenter {
name "jaspersoft-releases"
url "https://jaspersoft.jfrog.io/jaspersoft/jaspersoft-clients-releases"
}
}
I'd recommend switching from compile to implementation and using a shorthand to declare the dependency:
implementation "com.jaspersoft:jrs-rest-java-client:6.3.1:jar-with-dependencies"
Give a man a fish and you feed him for a day. Teach him how to fish and you feed him for his life time.
I decided to record a short clip of how I found the appropriate repositories for the artifacts you needed, on jfrog:

Vaadin 12 + Gradle 5 Create executable Fat jar

I need to use Jetty and Vaadin and build a fat jar.
My workspace is based around Gradle 5, Its a gradle multi module project
Parent
Common-Lib
Core-Lib
Jetty+Vaadin
I followed the documentation which i found here:
https://vaadin.com/tutorials/embedded-jetty-server-in-vaadin-flow
The documentation explains how to create Jetty's WebAppContext and start Jetty Server instance all based around maven.
Expect as i said my workspace is based around gradle, so instead of copying the pom.xml i rewrote it to the gradle build script which looks as follows:
plugins {
id 'idea'
}
group = 'some.example.jetty.and.vaadin.fatjar'
version = '1.0.0'
dependencies {
implementation project(':Core-Lib')
implementation project(':Common-Lib')
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
compile group: 'org.eclipse.jetty', name: 'jetty-continuation', version: '9.4.14.v20181114'
compile group: 'org.eclipse.jetty.websocket', name: 'websocket-server', version: '9.4.14.v20181114'
compile group: 'org.eclipse.jetty.websocket', name: 'javax-websocket-server-impl', version: '9.4.14.v20181114'
compile group: 'com.vaadin', name: 'vaadin-core', version: '12.0.7'
}
My problem is that during the build gradle outputs a .war file. I cannot use a .war file.
This project is supposed to be a plug-in module for another application, which i do not have sources for. The application just loads a jar files from specific folder, only jar extension is supported.
My question is: How can i create standard "unshaded" uber jar/fat jar instead of .war
With the word "unshaded" i want to unpack all JAR dependencies, and repack them into the final JAR.

Migrate maven dependencies to gradle

I start with software testing - using Cucumber, Java, gradle.
I try to learn this with the book "The Cucumber for Java Book"
But I try to do I with gradle instead of maven... But now I have some problems...
I stick on page 149. I have to give so dependecies:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
</dependency>
I try to "translate" this to gradle
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile 'io.cucumber:cucumber-java:2.4.0'
testCompile 'io.cucumber:cucumber-junit:2.4.0'
testCompile group: 'info.cukes', name: 'cucumber-picocontainer', version: '1.2.5'
compile group: 'org.eclipse.jetty', name: 'jetty-webapp', version: '9.4.12.v20180830'
}
Is this right?
compile group: 'org.eclipse.jetty', name: 'jetty-webapp', version: '9.4.12.v20180830'
After that I have to run:
mvn exec:java -Dexec.mainClass="nicebank.AtmServer"
But how can I do this with gradle?
I hope someone can help me :)
Your dependency looks good. Just one note: consider using implementation over compile as it improves the performance. Read about compile deprecation here.
You can also put your properties in gradle.properties file and reference them in the build script:
gradle.properties:
jettyVersion=9.4.12.v20180830
build.gradle:
implementation group: 'org.eclipse.jetty', name: 'jetty-webapp', version: jettyVersion
Jetty team also published BOMs: — org.eclipse.jetty:jetty-bom:9.4.12.v20180830 in your case. If you use multiple projects of the same version you can import the BOM and skip the version completely:
dependencies {
implementation 'org.eclipse.jetty:jetty-bom:9.4.12.v20180830'
implementation 'org.eclipse.jetty:jetty-webapp'
implementation 'org.eclipse.jetty:jetty-runner'
}
As for the "exec" task: if you have only one main class in your project, like nicebank.AtmServer, consider using Gradle's Application Plugin:
plugins {
id 'application'
}
mainClassName = 'nicebank.AtmServer'
This way you don't need to create "exec" task manually, you'll get one (run) from the plugin. As a bonus you'll get two "distribution" tasks that will create a ready-for-distribution archive with your app: distZip and distTar.
As I said in my comment, the dependency for jetty-webapp seems OK but you should use implementation instead of compile ( compile has been deprecated, see Java dependency configurations):
implementation group: 'org.eclipse.jetty', name: 'jetty-webapp', version: '9.4.12.v20180830'
or
implementation "org.eclipse.jetty:jetty-webapp:9.4.12.v20180830"
For the equivalent of "maven exec:java" in Gradle , you could use the Gradle JavaExec task type: try to define a task in your build as follows:
task runApp(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'nicebank.AtmServer'
}
(not tested, you migth have to adapt it) , and run it with
gradle runApp
You could alternatively use Gretty plugin to run your webapp (no need to define your own JavaExec task in this case), as documented here and here:
plugins{
// your existing plugins
id "org.gretty" version "2.2.0"
}
You can then run the application with:
gradle appRun

Is there a way to download dependencies jar from a Network location in Gradle 4.0?

Is there a way to download dependencies jar from a Network location in Gradle 4.0?
For example:
group 'com.hello'
version '1.0-SNAPSHOT'
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
compile 'https://<hostname>:port/hello.jar' // can I do this?
}
Gradle has had this capability before 4.0, but it requires you to establish your own Maven or Ivy repository.
https://docs.gradle.org/current/userguide/dependency_management.html#sub:maven_repo
While I'm sure you could alternatively write some standard Groovy code to simply download a jar into the libs folder

auto gradle downloading from svn repository

I have problems with configure my build.gradle for download jar and pom from svn repository. For example, i have url:
https://svn.code.sf.net/p/springframework/svn/repos/repo-ext/javax/xml/crypto/xmldsig/1.0/
and i want did like this compile group: 'com.sun.xml.wss', name: 'xws-security', version: '3.0'
Also, manual download is wrong way.
UPD this is build.gradle file of backend project
apply plugin: 'java'
dependencies {
compile group: 'org.glassfish.metro', name: 'wssx-api', version: '2.1.1-b09'
compile group: 'com.sun.xml.wss', name: 'xws-security', version: '3.0'
compile project(':pp-backend')
}
If you're not downloading from maven central (which is configured in Gradle by default), you should configure the repository to download from using the 'repositories' closure:
repositories {
mavenCentral()
maven {
url 'https://svn.code.sf.net/p/springframework/svn/repos/repo-ext/'
}
}
Then, in the 'dependencies' closure, just add:
compile group: 'javax.xml.crypto', name: 'xmldsig', version: '1.0'
See more info in Dependency Management Basics

Categories