Gradle clean<customTask> not working - gradle

I have a custom task to do a Websphere EJBDeploy. I have defined the inputs and ouputs, and get successful incremental compilation, but I can't get the automatically generated clean task to work properly.
According to docs, for a custom task named "ejbDeploy" with a defined output, a cleanEjbDeploy task should be automatically generated.
Pattern: clean<TaskName>: Cleans the output files of a task.
So here's my custom task:
task ejbDeploy(dependsOn: 'jar'){
srcFile = file(jar.archivePath)
destDir = new File("build/ejbDeploy")
inputs.file srcFile
outputs.dir destDir
def cp = project.files(
project.sourceSets.main.output.classesDir,
project.sourceSets.main.resources,
project.configurations.runtime
).getAsPath()
doLast{
destDir.mkdirs()
exec{
executable = wasEjbDeploy
workingDir = destDir
args = [
jar.archivePath,
".",
jar.archiveName,
"-cp",
cp
]
}
}
}
Anyone have any ideas as to why the clean rule isn't working?
[Edit]
Here's the full (anonymized) file contents (this has changed since initial question post):
version = '1.0-SNAPSHOT'
group = 'com.company'
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath group: 'name.benjaminAbbitt', name: 'WASEjbDeploy', version: '1.0-SNAPSHOT'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'base'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile 'javax.mail:mail:1.4.5'
compile 'log4j:log4j:1.2.16'
compile files(fileTree(dir: 'lib', includes: ['*.jar']) )
}
task ejbDeploy(type:name.benjaminAbbitt.WASEjbDeploy, dependsOn: 'jar'){
wasEjbDeployPath = wasEjbDeploy
}
Here's the relevant chunk of "$gradle tasks"
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend
on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles the main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles the test classes.
Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.
Help tasks
----------
dependencies - Displays the dependencies of project ':project'.
help - Displays a help message
projects - Displays the sub-projects of project ':project'.
properties - Displays the properties of project ':project'.
tasks - Displays the tasks runnable from project ':project' (some of the
displayed tasks may belong to subprojects).
IDE tasks
---------
cleanEclipse - Cleans all Eclipse files.
eclipse - Generates all Eclipse files.
Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.
Other tasks
-----------
ejbDeploy
Rules
-----
Pattern: build<ConfigurationName>: Assembles the artifacts of a configuration.
Pattern: upload<ConfigurationName>: Assembles and uploads the artifacts belongin
g to a configuration.
Pattern: clean<TaskName>: Cleans the output files of a task.
To see all tasks and more detail, run with --all.
BUILD SUCCESSFUL
Total time: 3.321 secs

The clean rule is provided by the base plugin. Since many other plugins (e.g. java) already apply the base plugin, you typically don't have to apply the base plugin yourself. But in case:
apply plugin: "base"

Related

IntelliJ Gradle deletes its own modules unexpectedly

This is the dialog indicating the modules which are being deleted
but when I import a new project with build.gradle and I do not enable auto import now I have a dialog asking my if I would like to enable auto import, and the modules are no longer deleted automatically.
Here is the build.gradle file
/*------------------------------------------------------------------------------
Gradle latest file.
Build command:
./gradlew deploy
Create Javadocs at ./latest/docs/javadoc/index.html
./gradlew buildJavadocs
Other commands of interest:
./gradlew wrapper --gradle-version 4.7
./gradlew tasks
./gradlew properties
Manual search for dependencies in Gradle repository:
https://bintray.com/bintray/jcenter/io.appium%3Ajava-client
------------------------------------------------------------------------------*/
group 'com.my.group'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceSets {
main {
java {
srcDir 'src/'
}
}
}
sourceCompatibility = 1.8
repositories {
jcenter()
}
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
compile 'junit:junit:4.12'
compile 'org.seleniumhq.selenium:selenium-java:3.11.0'
compile 'io.appium:java-client:6.1.0' // /compile 'io.appium:java-client:6.0.0-BETA5'
//compile 'io.appium:java-client:6.0.0-BETA5' // compile 'io.appium:java-client:6.1.0'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'com.google.guava:guava:24.1-jre'
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
}
task copyToLib(type: Copy, dependsOn: build) {
String dst = "$rootDir/jar"
description "Copy library JAR dependencies to $dst"
from configurations.runtime
into "$dst"
}
task copyToOut(type: Copy, dependsOn: build) {
String dst = "$rootDir/out"
description "Copy library JAR output to $dst"
from jar
into "$dst"
}
task deploy {
dependsOn clean
dependsOn build
dependsOn copyToLib
dependsOn copyToOut
}
task buildJavadocs(type: Javadoc) {
exclude 'srcOld/**'
classpath += sourceSets.test.compileClasspath
source += sourceSets.main.allJava
}
edit
When Gradle deletes the modules, it also delete gradle.build and the gradle wrapper. I've already created a brand new project with the default Java template, and copied and pasted my code into it, but the problem persists.
In case of a Gradle projects IDE configures the project structure including the modules that are included in project according your the build.gradle script. E.g. if you have Create separate module per source set option enabled in IDE Gradle settings IDE creates separate module for each Grale source set. It does it when re-importing build.gradle file. If you have auto-import enabled in IDE Gradle configuration it does it automatically.
Given the limited information, I'll give you an ad-hoc fix, just add -----test as a sub-project directory to your root projects settings.gradle using
include 'root-proj-dir:dir1:dir2:...:----test'
where the directory structure is
root-proj-dir
|
|
----dir1
| |
| |
| ----dir2
| |
| |
| ....----test
----settings.gradle
|
----build.gradle
For more info on dealing with multi-module (or multi-project in Gradle terminology ) builds refer this link

gradle: why there is no jar task for all sourceSets

Added sourceSet web, but there is no corresponding tasks for it:
apply plugin: 'java'
sourceSets {
web
}
Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.
webClasses - Assembles web classes.
I expected the following task
webJar
Gradle assemble and build: does not build web sourceSet.
there's not a jar task per sourceSet because in most projects this jar is not required. For example the java project comes with two sourceSets (main and test). A jar for the test sourceSet is not needed as you can run the tests without it.
If you need a jar for your additional sourceSet you can easily create one:
task myJar(type:Jar){
from sourceSets.mySourceSet.output
}

How to skip testRuntime task in gradle?

In my eclipse, there are many projects that build with gradle. I want to skip the testRuntime task in gradle. Because It's too slow and makes me wait for long time whenever I change some code or give changes the projects. How can I avoid this? I want to apply every relevant projects.
UPDATE
This is the result of gradle task. Eclipse is executing background job and I check these jobs in the process tab and I can see this message like the followings.
Gradle Build on xxx project
Executing tasks : xxxx:TestRuntime
I think It takes time because of firewall. I want to skip this process. I guess, It can be done by eclipse or by gradle configuration.
My build.gradle file
buildscript {
repositories {
mavenLocal()
maven { // for thridparty lib
url 'http://70.121.244.11:8081/nexus/content/groups/openpms-public'
credentials {
username 'openpms'
password 'openpms0'
}
}
maven { // for thridparty lib
url 'http://70.121.244.11:8081/nexus/content/repositories/thirdparty'
credentials {
username 'developer'
password 'developer0'
}
}
maven { url 'http://70.121.224.52:8081/nexus/content/repositories/central/' }
jcenter{ url 'http://70.121.224.52:8081/nexus/content/repositories/jcenter/' }
}
dependencies {
classpath "org.akhikhl.gretty:gretty:$gretty_version"
}
}
repositories {
mavenLocal()
maven {
url 'http://70.121.244.11:8081/nexus/content/groups/openpms-public'
credentials {
username "$maven_username"
password "$maven_password"
}
}
maven { // for thridparty lib
url 'http://70.121.244.11:8081/nexus/content/repositories/thirdparty'
credentials {
username 'developer'
password 'developer0'
}
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
sourceCompatibility = 1.6
targetCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' // compileGroovy, compileTestGroovy
def spring_version = '4.0.6.RELEASE'
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile group: 'org.opensymphony.quartz', name: 'quartz', version: '1.6.1'
compile group: 'commons-logging', name: 'commons-logging', version: '1.0.4'
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
}
gretty {
servletContainer = 'jetty8'
port = 8080
contextPath = '/agent.server'
}
UPDATE 2
[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks:
[sts] tasks
[sts] -----------------------------------------------------
<org.gradle.api.plugins.quality.PmdExtension_Decorated#729eaf4b __dyn_obj__=org.gradle.api.internal.AsmBackedClassGenerator$MixInExtensibleDynamicObject#2fc49256 __mapping__=org.gradle.api.internal.ConventionAwareHelper#1263649a __consoleOutput__=false __ignoreFailures__=true __reportsDir__=true __ruleSetConfig__=false __ruleSetFiles__=true __ruleSets__=true __sourceSets__=true __targetJdk__=false __toolVersion__=true project=root project 'redca-agent' ruleSets=[basic] targetJdk=null ruleSetConfig=null ruleSetFiles=file collection consoleOutput=false toolVersion=4.3 sourceSets=[source set 'main'] ignoreFailures=true reportsDir=D:\workspace\redCAGit\redca-agent\build\reports\pmd>
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Application tasks
-----------------
bootRun - Run the project with support for auto-detecting main class and reloading static resources
installApp - Installs the project as a JVM application along with libs and OS specific scripts.
run - Runs this project as a JVM application
Build tasks
-----------
assemble - Assembles the outputs of this project.
bootRepackage - Repackage existing JAR and WAR archives so that they can be executed from the command line using 'java -jar'
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles classes 'main'.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles classes 'test'.
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Distribution tasks
------------------
assembleDist - Assembles the main distributions
distTar - Bundles the project as a distribution.
distZip - Bundles the project as a distribution.
installDist - Installs the project as a distribution as-is.
Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.
Help tasks
----------
components - Displays the components produced by root project 'redca-agent'. [incubating]
dependencies - Displays all dependencies declared in root project 'redca-agent'.
dependencyInsight - Displays the insight into a specific dependency in root project 'redca-agent'.
help - Displays a help message.
model - Displays the configuration model of root project 'redca-agent'. [incubating]
projects - Displays the sub-projects of root project 'redca-agent'.
properties - Displays the properties of root project 'redca-agent'.
tasks - Displays the tasks runnable from root project 'redca-agent' (some of the displayed tasks may belong to subprojects).
Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.
Other tasks
-----------
findbugsTest - Run FindBugs analysis for test classes
pmdTest - Run PMD analysis for test classes
Rules
-----
Pattern: clean<TaskName>: Cleans the output files of a task.
Pattern: build<ConfigurationName>: Assembles the artifacts of a configuration.
Pattern: upload<ConfigurationName>: Assembles and uploads the artifacts belonging to a configuration.
To see all tasks and more detail, run gradle tasks --all
To see more detail about a task, run gradle help --task <task>
BUILD SUCCESSFUL
Total time: 2.354 secs
[sts] -----------------------------------------------------
[sts] Build finished succesfully!
[sts] Time taken: 0 min, 2 sec
[sts] -----------------------------------------------------
I want to know the way to skip working testRuntime.
Even if it is not task, my concern is not to waste time.
How can I avoid this?
I am a newbie in gradle and I am not goot at English. Please understand.
Anyway, I solved by myself. Eclipse gradle plugin, I am using, is trying to connect the repository on the internet that may be blocked by firewall. So I can't solve this. There are many workplaces including the place where is offline.
I could skip this giving the parameter to Program Arguments like the followings. you can add this property in eclipse preference > Gradle > Arguments.
--offline

Gradle. Multi-project with Web. How to include dependent projects as class files into web-inf/classes

I use the Eclipse IDE to develop the following java eclispe projects:
"AuthRESTService" - The development of REST service
"AuthZcommon" - The Utilities, used cross over projects.
"AuthCore" - the core functions.
The needed external libs are placed into simple project "AuthLibs"
The AuthRESTService depends on AuthCore and AuthZcommon.
AuthCore depends on AuthZcommon.
i need to have the WAR file, that contains NOT AuthZcommon.jar and AuthCore.jar
I need to have the WAR file with class files for that projects.
Currently i have the JARs....
===AuthRESTService - settings.gradle==========
includeFlat 'AuthZcommon', 'AuthCore'
===AuthRESTService - gradle.buid==========
apply plugin: 'java'
apply plugin: 'war'
project.webAppDirName = 'WebContent'
def directories = '../AuthLibs/lib'
dependencies {
providedCompile fileTree(dir: directories)
compile project(':AuthZcommon')
compile project(':AuthCore')
war {
description "Create a war file for the web-application release"
classpath fileTree(dir: directories, exclude: ['**/servlet-api*.jar','**/*test-common.jar'])
}
}
==========/AuthCore - settings.gradle==========
includeFlat 'AuthZcommon'
==========/AuthCore - build.gradle=======
apply plugin: 'java'
def directories = '../AuthLibs/lib'
println directories
repositories {
flatDir(dir: directories , name: 'libs directory')
}
dependencies {
compile fileTree(directories)
compile project(':AuthZcommon')
}
==========

Gradle Release System Task - Calling uploadArchives on subprojects

In order to release my system, I am creating a releaser project that calls uploadArchives for a number of other projects.
In my project I have the following files:
settings.gradle
include '../proj-a', '../proj-b'
build.gradle
task releaseSystem() {
// what goes here?
}
What should the contents of the releaseSystem task be such that I can call gradle releaseSystem and have it run uploadArchives for each of my sub projects?
I've tried a number of options, but none have been successful thus far.
Thank you for any insights you can provide.
ANSWER
I'm continually impressed with the graceful solutions gradle provides to my problems. Here's my final solution (as Peter pointed out below):
settings.gradle
include 'proj-a', 'proj-b'
project (':proj-a').projectDir = new File(settingsDir, '../proj-a')
project (':proj-b').projectDir = new File(settingsDir, '../proj-b')
build.gradle
task releaseSystem() {
dependsOn {
[
subprojects.build,
subprojects.uploadArchives
]
}
}
Note, that since my repository is a maven repository, when I originally included '../proj-a' in my settings.gradle, it produced poms with artifactId ../proj-a which was invalid. I had to change my settings.gradle to the format above for the system to put the poms together correctly and for the uploadArchives task to complete successfully.
Assuming all subprojects have an uploadArchives task:
task releaseSystem {
dependsOn { subprojects.uploadArchives }
}
Note that this won't run the subprojects' tests.

Resources