Clean task not found in gradle - gradle

I have a gradle build file and am not able to execute a build. I am working with old code and the code should be built with 1.0-milestone-7 version since other projects use this version.
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'base'
apply plugin: 'application'
assert gradle.gradleVersion == '1.0-milestone-7'
mainClassName = "my.ClassTest"
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
}
test {
systemProperties = System.properties
}
c:\work\gradletest\> gradle clean
FAILURE: Could not determine which tasks to execute.
* What went wrong:
Task 'clean' not found in root project 'gradletest'.
* Try:
Run gradle tasks to get a list of available tasks.
Anything I forgot?

Changing the filename to build.gradle solves the issue. Note that this is the case in 1.0-milestone-7.

Related

Setting up dependencies for publish tasks

I programmatically create maven-publish publications and would like those to depend on a custom task. I have tried the following:
apply plugin: 'java'
apply plugin: 'maven-publish'
publishing.publications.create("A", MavenPublication) { groupId = "G" }
task t
afterEvaluate { publishToMavenLocal.dependsOn(t) }
Doing a gradle publishToMavenLocal does result in t running before publishToMavenLocal but the generated task, publishAPublicationToMavenLocal, runs before t which is not what I want. I have tried setting up dependencies by iterating all tasks with names beginning with publish. This does not work either since publishAPublicationToMavenLocal is not available in the afterEvaluate phase.

How to force artifact/module name with Gradle build

Please note: even though this question specifically mentions Bamboo CI and the Gradle ShadowJar plugin, I believe this is a basic Gradle config question at heart, and believe it can be answered by any battle-weary Gradle Guru.
I have a Groovy app that is built with Gradle, where build.gradle is:
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'eclipse'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
group = 'com.me.myapp'
mainClassName = "com.me.myapp.MyAppDriver"
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.0'
}
}
dependencies {
// Omitted for brevity
}
jar {
manifest {
attributes 'Main-Class': mainClassName
}
}
repositories {
mavenLocal()
mavenCentral()
}
shadowJar {
classifier = ''
mergeServiceFiles {
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
}
}
artifacts {
archives(file("${buildDir}/libs/myapp-${version}.jar")) {
name "myapp"
classifier ""
builtBy shadowJar
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
And where gradle.properties is:
group=com.me.myapp
version=1.0.0
As you can see, I'm using ShadowJar to produce a self-contained "fat JAR" for my app. When I run gradle clean build shadowJar on my local machine, Gradle produces a build/libs/myapp-1.0.0.jar artifact/archive. However, when this same command is ran from our CI server (Bamboo), Gradle produces a build/libs/MYAPP-KEY-1.0.0.jar artifact/archive, where MYAPP-KEY is the Bamboo "build key" (essentially, a unique key/label identifying the build on the server). If you're clueless as to what I'm talking about, I don't think that really matters. What is important to understand is that Bamboo will check out the source code for myapp to a folder named MYAPP-KEY on the CI server. So locally myapp/ is the root of my project, but on CI MYAPP-KEY is the root of my project.
The main point is that I am not explicitly defining something in my Gradle config, and so it seems that Gradle is using the name of the project root to produce the name of the built JAR. What is this "something" and how/where do I define it? The desired end objective is to produce a build/libs/myapp-1.0.0.jar both locally and on CI.
please, look at https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html
you can specify base name or full archive name of jar
add it to your jar section

Gradle task to put jars from Maven repository into project lib folder

http://blog.jonasbandi.net/2014/03/running-nodejs-applications-on-jvm-with.html describes how to prepare to run Avatar.js project.
For a Avatar.js project some jar and native binaries are at maven repository https://maven.java.net/content/repositories/public/com/oracle/
I'd like to use gradle task to get jars from Maven repository and put into lib folder.
The research show it is possible.
http://forums.gradle.org/gradle/topics/create_a_local_mirror_for_dependencies
http://gradle.1045684.n5.nabble.com/collecting-only-external-dependency-files-td5117615.html#a5680602
Is there some more standard implementation of such task as of April 2014 ?
UPDATE:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
repositories {
maven {
url "https://maven.java.net/content/repositories/public/"
}
}
dependencies {
compile "com.oracle.avatar-js:avatar-js:0.10.+"
}
task copyLibs(type: Copy) {
from configurations.compile
into 'lib'
}
Sample script:
apply plugin: 'java'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:16.0.1'
}
task copyLibs(type: Copy) {
from configurations.compile
into 'lib'
}

How do I download my Gradle project external dependencies to a specific folder?

I want to download my dependencies to a specific folder in my build as part of my build process e.g. build/lib . I can't find documentation which shows how to do this, I'm sure there is a straightforward way to do it that I'm missing. My current(shortened) build.gradle is the following. The project compiles and executes test correctly.
apply plugin: 'java'
apply plugin: 'maven-publish'
repositories {
mavenCentral()
}
dependencies {
compile(
'aopalliance:aopalliance:1.0',
'log4j:log4j:1.2.17',
'batik:batik-svg-dom:1.6-1')
}
}
I dont know if you tried this, but see if this works
task copyToLib(type: Copy) {
into "$buildDir/output/lib"
from configurations.runtime
}
build.dependsOn copyToLib
It worked for me.
Credit where its due :-) : http://forums.gradle.org/gradle/topics/how_can_i_gather_all_my_projects_dependencies_into_a_folder

Running Gradle plugin directly from command line

In Maven, if I wanted to analyze my project with sonar, I could do:
mvn sonar:sonar
using the 'short' plugin name and goal.
In Gradle, is there a similar way to run plugins, without declaring them in the build.gradle script?
This code works fine:
allprojects {
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5"
}
}
apply plugin: 'java'
apply plugin: 'jacoco'
afterEvaluate { project ->
project.apply plugin: 'org.sonarqube'
}
}
gradle --init-script etc/quality.gradle sonarqube
There isn't currently, but there will be at some point. What you can do is to apply the plugin out-of-band (in some init.gradle).

Resources