How to make a copy in the resources/app folder. After the other module is compiled
jar {
dependsOn(project(':portal-frontend').tasks.findByName("compileGwt"))
into("app") {
File configFile = file(project(':portal-frontend').tasks.findByName("compileGwt").buildDir)
println configFile.listFiles()
from project(':portal-frontend').tasks.findByName("compileGwt").buildDir
//from compileGwt.buildDir
}
}
}
I have 2 submodule portal-backend and portal-frontend
portal-backend - spring boot project
portal-frontend - gwt project
So I want. When portal-frontend compile. Copy build resource from portal-frontend to portal-ackend
Something like this https://gist.github.com/marcokrikke/5481001
But I have multimodule structure
Related
I am currently trying to create a bundle with bnd in a Gradle project.
The idea was to try getting the list of jar dependencies with Gradle and modify the jar task to add the libs inside the bundle.
Let's say, I would like to remove the includeresource.
-includeresource: lib/jsoup.jar=jsoup-1.14.3.jar
Bundle-ClassPath: ., lib/jsoup.jar
I tried some variations of:
jar {
duplicatesStrategy = 'EXCLUDE'
from {
configurations.runtimeClasspath.findAll {
it.name.endsWith('jar')
}.collect { println it.name; zipTree(it) }
}
}
I can see the name of the jar being printed, but not included inside the bundle, (I know zipTree would expand).
Suggestions from https://discuss.gradle.org/t/how-to-include-dependencies-in-jar/19571/16 do not seem to be valid for bnd, and I suspect bnd overrides the jar task somehow.
A suggestion as:
jar {
def libBuildDir = mkdir "${buildDir}/resources/main/lib"
copy {
from { configurations.jarLibs }
into { libBuildDir }
}
}
Would be perfect, but it does not seem to work for bundles.
Any ideas?
I was trying plugins:
io.freefair.war-overlay - but it just overlay one war to another,
waroverlay - it has appropriate option "includeWarJars true" but it
does't works for me.
Currently I'm trying write script:
dependencies {
/* jar, his files I would like to include in war */
compile project(':my_jar_1')
}
war {
/* Step 1. Copy all from my_jar_1 into WEB-INF/classes */
into('WEB-INF/classes') {
from configurations.compile
.filter { it.name.startsWith("my_jar_1") }
.collect { zipTree(it).matching { exclude 'META-INF/**/*.*' }}
}
/* Step 2. Deleting jar from war WEB-INF/lib. I got stuck here. It println, but doesn't delete jar */
doLast {
zipTree('build/libs/war_1-0.0.0.war').files.each {
if (it.path.endsWith('.jar')) {
delete it
println 'DELETED ' + it.path
}
}
}
}
Could somebody tell me how to make it work?
Or maybe smb know more elegant solution?
Also I was trying to declare my own configuration
configurations { overlay }
dependencies {
overlay project(':my_jar_1')
}
war {
into('WEB-INF/classes') {
from configurations.overlay
...
But it shows error
FAILURE: Build failed with an exception.
What went wrong: Failed to capture snapshot of input files for task 'war' property 'rootSpec$1$1' during up-to-date check.
Failed to create MD5 hash for file '/home/user/projects/OveralJarToWar/my_jar_1/build/libs/my_jar_1-1.0-SNAPSHOT.jar'.
The content of WEB-INF/lib and WEB-INF/classes is configured by single property classpath of war task. According to documentation:
Any JAR or ZIP files in this classpath are included in the WEB-INF/lib directory. Any directories in this classpath are included in the WEB-INF/classes directory
So, in your case, the classpath should be modified as follow
war {
def myJar = project(':my_jar_1').jar.outputs
def myClassesAndResources = project(':my_jar_1').sourceSets.main.output
classpath = classpath - myJar + myClassesAndResources
}
I have an android project that contains different library modules. I defined a task which uploads artifacts to a maven repository. It works when I define it directly in the build.gradle of the modules. What I would like to do is to define the task once in the parents build.gradle and reuse it in each module.
I followed the guide here to write following build configuration:
My project setup is like this:
parent_project
|- module1
|- module2
|- module3
parent/build.gradle, default
subprojects {
task installToLocalMaven(type: Upload) {
description "Installs artifacts to local Maven repository"
configuration = configurations['archives']
repositories {
mavenDeployer {
pom.groupId = commonGroupId
pom.artifactId = artifactId
pom.version = gitBranch() + '-' + android.defaultConfig.versionName
if (android.defaultConfig.versionName.endsWith("-SNAPSHOT")) {
snapshotRepository(url: repositories.mavenLocal().url)
} else {
repository(url: repositories.mavenLocal().url)
}
}
}
}
}
project(':module1') {
ext.artifactId = "module1"
}
...
Executing gradlew :module1:installToLocalMaven leads to this Error Configuration with name 'archives' not found.
I assume that the configuration object from the parent project is used.
How can I make sure that the configurations object of the child module is used from within the parents build.gradle?
You can use the task's project property. Just add task.project. in front of the sub-project object you are trying to access like this:
configuration = task.project.configurations['archives']
I'm trying to get Gradle to handle the deployment of a very large Web application. In the past when we used Ant, instead of creating a very large .war file, we would simply assemble all the code in one folder--libraries, .jsp's etc--and then scp them to the deployment destination. This would speed deployment since we would be moving only the files that changed.
I'm having trouble trying to do this with Gradle, however. Using the War plugin creates an actual .war file, which we don't want. I've tried simply creating a task that depends on 'classes' and that generates the necessary classes and resources folders. However, where are the library dependencies? How can I get this all in one place so I can do an scp?
Current build:
apply plugin: "java"
apply plugin: "maven"
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
sourceCompatibility = 1.6
targetCompatibility = 1.6
repositories {
maven {
url 'http://buildserver/artifactory/repo'
}
}
sourceSets {
main {
java {
srcDir 'src'
}
resources {
srcDir 'src'
}
}
}
webAppDirName = 'web'
dependencies {
compile 'antlr:antlr:2.7.6'
compile 'antlr:antlr:2.7.7'
*** etc ***
}
task deploystage(dependsOn: 'classes') << {
println 'assemble and scp code here'
}
your right Opal ... no easynway to use the War plugin for this ... although it would be nice if it had a createExplodedWar option. I just used the Jar plugin methods.
The .jars were available, along with other things in war.classpath.files:
gradle.taskGraph.whenReady { TaskExecutionGraph taskGraph ->
project.ext.set("allclasspathjars", files(war.classpath.files))
}
I then when through these to separate out the .jars from the other stuff:
task deployJars(dependsOn: 'classes') << {
FileUtils.cleanDirectory(new File("web/WEB-INF/lib/"))
project.allclasspathjars.each {File file ->
if(file.name.endsWith(".jar")) {
println "Including .jar: " + file.name
org.apache.commons.io.FileUtils.copyFile(file, new File("web/WEB-INF/lib/" + file.name))
}
}
After this I could copy all the classes & resources into the .war structure:
task createExplodedWar(type: Copy, dependsOn: 'deployJars') {
from 'build/classes/main'
from 'build/resources/main'
into 'web/WEB-INF/classes'
}
Finally used Gradle SSH Plugin to push it up to tomcat and restart the server.
All good.
We have recently started using Gradle(1.12) to build our application components and the first place we have started is by doing EJB Deploy. This is what we are trying to achieve:
compile a sourceSet which is located at project directory /ejbModule ( This consists of the java classes and META-INF folder which contains ejb-jar.xml and other websphere related xml's.
Create a jar which will contain the above package and resources
run ejbdeploy.bat located at %WAS_HOME%\bin which takes input as jar created in step 2 which will create stubs / skeletons and re-package the jar at a different directory.
Now this is my gradle build file
def wasHome = 'C:/Data/IBM/WebSphere/AppServer'
def internalClasses = 'C:/GoldCopy1/Workspace/chimessharedlib'
def appPath = 'C:/GoldCopy1/Workspace/IEApp'
apply plugin:'java'
repositories {
flatDir {
dirs wasHome + '/lib'
dirs internalClasses
dirs appPath
}
}
dependencies {
compile name : 'j2ee'
compile name : 'commons-lang-2.3'
compile name : 'FW'
compile name : 'Common'
compile name : 'DA'
compile name : 'ST'
}
sourceSets {
main {
java {
srcDir '/ejbModule'
}
resources {
srcDir '/ejbModule'
}
}
}
task runEJBDeploy (type:Exec) {
commandLine wasHome + '/bin/ejbdeploy.bat', '/C'
def inputJar = "" + libsDir + File.separator + 'AR.jar';
println inputJar;
def argsList = [inputJar, "C:\\tpp" , "C:\\tpp\\deploy\\AR.jar" , "-complianceLevel", "5.0"]
args = argsList;
}
So by running the runEJBDeploy task above, I want to generate a command like below:
ejbdeploy.bat -cp "C:\tpp\FW.jar;C:\tpp\DA.jar;C:\tpp\Common.jar" C:\tpp\AR.jar C:\tpp C:\tpp\deployed\AR.jar -complianceLevel 5.0
So since FW, DA and Common are already provided in the dependencies { } section of the build.gradle file, is there a way to use those dependencies for appending it after "-cp " and then run the command?
I am very new to gradle so please also point out any other wrong approach taken which should be improved.
Thanks in advance