gradle publishing project-version-PLAIN.war file instead of project-version.war - java

When I run "gradle build", it generates a build/libs/project-version.war file which is able to run by itself with "java -jar" command. But when I run "gradle artifactoryPublish", it saves on the artifactory repository a "project-version-plain-war" file which does not have tomcat embedded.
I am following this instruccions https://www.jfrog.com/confluence/display/JFROG/Gradle+Artifactory+Plugin
The lines added to the gradle.build are something like this:
plugin "maven-publish"
plugin "com.jfrog.artifactory"
artifactory {
...
}
subprojects {
plugin "war"
group = group
version = version
publishing {
publications {
MavenPublication(MavenPublication) {
from components.web
}
}
repositories{
maven { url "https://artifactory-server" }
}
}
}
help is appreciated

Using from components.web means that you are publishing the artifact produced by the war task. You need to publish the artifact produced by the bootWar task. You can do so by changing the publication to use artifact bootWar instead:
publishing {
publications {
MavenPublication(MavenPublication) {
artifact bootWar
}
}
repositories{
maven { url "https://artifactory-server" }
}
}
This is described in the reference documentation for Spring Boot's Gradle plugin.

Related

Gradle maven publish plugin fails in a multi-module project with error "Artifact wasn't produced by this build"

I have a multi-module project which supports maven and gradle builds hence it contains pom.xml files along side with build.gradle. I'm working on a demo and I would like to show how to build and deploy to nexus the same project using either gradle or maven. That's why I have two different build systems in case you wonder why.
You may see the project structure below.
You may look into the code here.
I've configured the gradle maven-publish plugin in order to publish all modules to my local nexus repository however when I run gradle publish I hit this error:
Execution failed for task ':publishMavenJavaPublicationToMavenRepository'.
> Failed to publish publication 'mavenJava' to repository 'maven'
> Artifact machinery-config-0.0.1.jar wasn't produced by this build.
The issue is related with having the publishing section within $rootDir/build.gradle.
It's confusing maven-publish somehow which is trying to publish an artifact that doesn't exist machinery-config-0.0.1.jar, machinery-config is the name of the rootProject.
One workaround could be to remove the publishing section from the rootProject and duplicate it in the sub-projects. I don't like that approach cuz I will end up with a lot of duplicated code.
Could you point me out a better way to use maven-publish within a multi-module project ?
After some digging I realized that I had two issues:
publishing section was outside of subprojects section, then gradle tried to deploy an artifact using rootProject.name ignoring the included modules.
group & version properties were outside subprojects therefore deployed artifacts had undefined as version number, e.g machinery-config-core-undefined.jar
In order to fix issue number two I had moved group & version into subprojects section.
My build also produces a BOM artifact hence I need two publications from components.java and from components.javaPlatform, so I wrote this script gradle/ext/publish-common.gradle which exports two functions I will use later on both publications to keep code duplication at bay.
def pom(it) {
it.licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
it.developers {
developer {
id = 'eljaiek'
name = 'Eduardo Eljaiek'
email = 'eduardo.eljaiek#gmail.com'
}
}
it.scm {
connection = 'scm:git:git://github.com/eljaiek/machinery-config.git'
developerConnection = 'scm:git:git#github.com:eljaiek/machinery-config.git'
url = 'https://github.com/eljaiek/machinery-config'
}
}
def nexusRepository(it) {
it.url = version.endsWith('SNAPSHOT') ? project.nexusSnapshotsUrl : project.nexusReleasesUrl
it.credentials {
username project.nexusUser
password project.nexusPasswd
}
}
ext {
pom = this.&pom
nexusRepository = this.&nexusRepository
}
I had added from components.javaPlatform publication into machinery-config-dependencies/build.gradle in order to deploy the BOM artifact
apply plugin: 'maven-publish'
apply from: "$rootDir/gradle/ext/publish-common.gradle"
publishing {
publications {
mavenBom(MavenPublication) {
from components.javaPlatform
pom { x -> pom(x)}
}
}
repositories {
maven { x -> nexusRepository(x) }
}
}
apply from: "$rootDir/gradle/ext/publish-common.gradle" will aplly the script I wrote, this is required in order to import pom() and nexusRepository() functions into my build script.
To deploy from components.java artifacts I had added a publishing section in subprojects under if (it.name != 'machinery-config-dependencies') statement into $rootDir/build.gradle
apply plugin: 'ru.vyarus.pom'
apply from: "$rootDir/gradle/ext/publish-common.gradle"
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom { x -> pom(x)}
}
}
repositories {
maven { x -> nexusRepository(x) }
}
}
I had used Gradle POM plugin instead of maven-publish. It provides maven's dependencies declaration simplicity and implicitly applies maven-publish plugin.
See the code here
References
Extract common methods from Gradle build script
The Java Platform Plugin

How to publish gradle subproject to Maven local repository?

My build.gradle looks like this
configurations {
bukkitPlugin
...
}
dependencies {
bukkitPlugin(project(':IslandCraft-Bukkit'))
bukkitPlugin(project(':IslandCraft-NMS-v1_12_R1'))
bukkitPlugin(project(':IslandCraft-NMS-v1_13_R1'))
}
task bukkit(type: ShadowJar) {
description = 'Create the IslandCraft Bukkit plugin JAR'
group = project.group
baseName = project.name
appendix = 'Bukkit'
version = project.version
configurations = [ project.configurations.bukkitPlugin ]
from {
project.configurations.bukkitPlugin
}
relocate 'org.mcstats', 'com.github.hoqhuuep.islandcraft.mcstats'
}
publishing {
publications {
bukkitPlugin(MavenPublication) { publication ->
shadow.component(publication)
}
}
}
gradle bukkit works fine and builds all that I need but gradle publishToMavenLocal saves jar with META-INF only on my local repository. How can I install the build to local repository?

Why can't Gradle find existing artifact?

I posted the same question at the Gradle Forums Gradle can not find existing artifact?.
Gradle v4.10.2
This really bothers me, since I know it should work, and I feel like I’m setting up my build.gradle file correctly.
I built a plugin and deployed it to our AWS S3 Maven repo.
When I run a Gradle command, e.g., ./gradlew clean, I get
Here's my build.gradle file
buildscript {
repositories {
maven {
url s3_bucket
credentials(AwsCredentials) {
accessKey AWS_ACCESS_KEY
accessKey AWS_SECRET_KEY
}
}
}
dependencies {
classpath "com.zift.utilities:zift-version-plugin:0.0.1"
}
}
plugins {
id 'java'
id 'maven'
id 'maven-publish'
id 'java-gradle-plugin'
}
version = '0.0.1'
jar {
manifest {
attributes 'artifactId': project.artifactId,
'groupId': project.groupId,
'version': project.version
}
baseName artifactId
doLast {
println "artifactId: $project.artifactId\ngroupId: $project.groupId\nversion: $version"
}
}
If I comment out the classpath line (the problematic line), I get
$ ./gradlew build
> Task :jar
:jar: No valid plugin descriptors were found in META-INF/gradle-plugins
artifactId: zift-version-plugin
groupId: com.zift.utilities
version: 0.0.1
What am I missing?

write a gradle script that saves all the dependency into the ${projectDir}/lib folder

So I have a gradle script which gets all its dependencies from the following repository
repositories {
maven { url 'http://repository.paychex.com:8081/artifactory/repo1-cache' }
ivy { url 'http://repository.paychex.com:8081/artifactory/repo1 cache'
layout 'pattern', {
artifact '[organization]/[module]/[revision]/[type]/[module]-[revision].jar'
}
}
mavenlocal()
}
so when I run a customized gradle task which i wrote as
task showMeCache << {
configurations.compile.each { println it }
}
It will show that my jars are being saved locally on
C:\Users\Administrator.gradle\caches\modules-2\files-2.1***
I want to write a gradle task that will put all the dependencies for a given project into something like a ${projectDir}/lib folder instead of the default location provided by gradle. Any help would be appreciated. Thanks
You can write a Copy task for that purpose:
task copyLibs(type: Copy) {
from configurations.compile
into 'lib'
}
Keep in mind that would still download and use the resolved dependencies from the Gradle cache.

How to publish programmatically manipulated (e.g. instrumented) jars in Gradle?

I have a multi-project build. Sub-project CoolApp depends on sub-project CrazyJar. Project CrazyJar has no sources: it uses a tool to perform byte code manipulation on an existing jar derived from non-Gradle project BigProject and wishes to publish the resulting manipulated jar to be depended on by CoolApp. It needs to publish this as a local Maven package.
Since it seems the "maven-publishing" plugin only supports "java" and "web" projects, I apply the "java" plugin to CrazyJar. But CrazyJar has no sources! I end up publishing an empty artifact. Is there any way I can mangle this to work as though it were a normal Java project? If not, anything else I might do?
Hmm, yeah, I misunderstood my problem slightly. Well, here was my solution anyway (based mostly off documentation for the "maven-publish" plugin):
Root project
subprojects {
repositories {
maven {
url "${rootDir}/repo"
}
}
}
CrazyJar project
apply plugin: "maven-publish"
...
task createCrazyJar(type: Exec) {
...
}
publish {
dependsOn "createCrazyJar"
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact createCrazyJar.outputs.getFiles().getSingleFile()
}
}
repositories {
maven {
url project.repositories.maven.url
}
}
}
CoolApp project
dependencies {
compile group: "coolproject", name: "crazyjar", version: project("CrazyJar").version
}

Categories