Gradle Plugin output name - gradle

How could I set output name when Gradle builds custom plugin artifact?
I mean when I create a custom plugin and build it Gradle puts plugin-name-1.0.0.jar into build/libs folder.
By default it gets final .jar name from the project folder name.
But I'd like to set it a custom name.
Thanks.

try this :
jar {
baseName = 'custom-name'
}
You will get custom-name-1.0.0.jar

Related

How to create a Zip file using gradle 2.3

I have my archive at location myProject/unzip and need to:
Zip the contents within the unzip folder and create a zip file with some name at any location within the project.
Using gradle 2.3.
Can anyone help me for this?
I am not sure what you are doing differently than the examples in the documentation from the link I gave in the comments. But this works for me with Gradle 2.3:
task myZip(type: Zip){
from "$projectDir/unzip"
archiveName = "my-zip.zip"
destinationDir = buildDir
}
The input folder is called unzip and needs to present as a child in the project folder. It outputs a file my-zip.zip in the build folder.
Be sure that there actually are some resources located in the from path, or Gradle might skip it.

Make a simple JAR in gradle

I am new to gradle builds. I wrote a custom service for cloudera manager which needs to build a JAR file with few directories. It is a simple archive file with few directories(descriptor, images and scripts). I created it with below jar command manually.
jar -cf CSDNAME.jar descriptor images scripts
Now I want to include this as part of gradle build for which I need to write a task. I searched online where I found java related stuff which is not required in my case. Can someone help with this?
That's a code snippet using the kotlin dsl. It's based on the JAR task of the java plugin.
plugins {
java
}
tasks.jar {
doFirst {
archiveBaseName.set("CSDNAME") // By default the JAR will have the project name
from("content") // source folder where you have your content
}
}
N.B: If you already have a build file, you will need to change its extension to .kts, else you'll need of course to create one.

How to create directory and move WAR file using Gradle

By default, Gradle puts all WAR files that it creates in build/libs when I run gradle build on a Java project. How do I instruct Gradle to create a directory called dist under build and put all WAR files in that directory (i.e. build/dist)?
I created a new task called moveWar that accomplished what I wanted:
task moveWar(type: Copy) {
from 'build/libs'
into 'build/dist'
}
Then I used build.finalizedBy moveWar to move the WAR file in libs to dist after the build is finished.
Another approach I found:
war.destinationDir = file "$buildDir/dist"

copy release aar file after succeful build

when building an aar file using gradle, how can I copy the created release aar to some other directory ?
(I do not want to change the default output dir just to copy the release file )
Assuming you are not using any flavors, and you are not changing the AAR name, you can use something like the following task:
task copyAAR(type: Copy) {
from('build/outputs/aar')
into('/path/to/desired/output/dir')
include(project.name + '-release.aar')
}
If you changed the AAR name, replace 'project.name' with that name.

How Do I Change The Gradle Output Directories?

Maven puts its output in "target". Gradle puts its output in "build".
How can I make gradle put its output in "target" too?
The output of the war plugin is "build/libs/project.war"; how can I make it "target/project.war"?
Have a look at the javadocs or the userguide. There's a method setBuildDir. You need to pass a path where you want artifacts to be placed.
e.g.
// Use maven output dir
setBuildDir 'target'
Wicket is an example of a project that does this.

Resources