marcos_aps
(Marcos Antonio Pereira Silva)
November 24, 2015, 12:55pm
1
In my multiproject project I’m giving different names to my projects than the folder name. This is the contents of my settings.gradle file:
include 'eventos', 'modelo', 'negocio', 'negocio-impl', 'persistencia', 'persistencia-impl', 'visao'
rootProject.children.each {it.name = "eventos-" + it.name}
This is working well, but I noticed that the generated archives (ear, war, jar) are being named ‘eventos-eventos.ear’ , ‘eventos-visao.war’ , ‘eventos-persistencia.jar’ etc. I don’t want this. I would like to strip the prefix ‘eventos-’ from all this archives as was the case when the project names were the same as the folder names. How can I achieve this?
Thank you.
sterling
(Sterling Greene)
November 24, 2015, 3:39pm
2
You should be able to change the archivesBaseName (it defaults to the project name):
https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:archivesBaseName
e.g., something like:
subprojects {
archivesBaseName = project.name - 'eventos-'
}
marcos_aps
(Marcos Antonio Pereira Silva)
November 24, 2015, 3:54pm
3
Hello, sterling.
I’m using this code, based on yours, and almost everything is working fine:
subprojects {
tasks.withType(Jar) {
archivesBaseName = archivesBaseName - "eventos-"
}
tasks.withType(War) {
archivesBaseName = archivesBaseName - "eventos-"
}
tasks.withType(Ear) {
archivesBaseName = archivesBaseName - "eventos-"
}
}
The problem is that now my application.xml file in the ear file has two entries for the web module:
<?xml version="1.0"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="6">
<module>
<web>
<web-uri>eventos-visao.war</web-uri>
<context-root>eventos</context-root>
</web>
</module>
<module>
<web>
<web-uri>visao.war</web-uri>
<context-root>visao</context-root>
</web>
</module>
<module>
<ejb>negocio-impl.jar</ejb>
</module>
<library-directory>lib</library-directory>
</application>
Before changing the names it was only this:
<module>
<web>
<web-uri>visao.war</web-uri>
<context-root>eventos</context-root>
</web>
</module>
Is there a way to fix this? I would like to understand what’s going on.
marcos_aps
(Marcos Antonio Pereira Silva)
November 24, 2015, 5:35pm
4
For some reason it is working now, with the same code. By the way, is there a way to simplify this code to eliminate the duplication between the tasks?
subprojects {
tasks.withType(Jar) {
archivesBaseName = archivesBaseName - "eventos-"
}
tasks.withType(War) {
archivesBaseName = archivesBaseName - "eventos-"
}
tasks.withType(Ear) {
archivesBaseName = archivesBaseName - "eventos-"
}
}
jjustinic
(James Justinic)
November 24, 2015, 8:40pm
5
Have you tried to do this with just the task.withType(Jar) {...}
closure? The War
and Ear
tasks both extend Jar
so task.withType(Jar) {...}
should already be providing those two other task types to you as well. Temporarily throw println it
into the closure if you want to verify exactly which tasks are being affected with this code.
subprojects {
tasks.withType(Jar) {
archivesBaseName = archivesBaseName - "eventos-"
}
}
1 Like
marcos_aps
(Marcos Antonio Pereira Silva)
November 25, 2015, 11:37am
6
Before your solution I was using:
subprojects
{
def nomeBaseArquivos = {archivesBaseName = archivesBaseName - "eventos-"}
tasks.withType(Jar) {configure nomeBaseArquivos}
tasks.withType(War) {configure nomeBaseArquivos}
tasks.withType(Ear) {configure nomeBaseArquivos}
}
but your solution is far better as ear and war tasks are also jar tasks. Thank you.