# How to remove a prefix from the archive names for all subprojects?

**URL:** <https://discuss.gradle.org/t/how-to-remove-a-prefix-from-the-archive-names-for-all-subprojects/12918>\
**Category:** Buildship\
**Tags:** issue-resolved\
**Created:** [November 24, 2015, 12:55pm UTC](https://discuss.gradle.org/t/how-to-remove-a-prefix-from-the-archive-names-for-all-subprojects/12918 "2015-11-24T12:55:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcos\_aps](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@marcos\_aps](https://discuss.gradle.org/u/marcos_aps)\
**Post date:** [November 24, 2015, 12:55pm UTC](https://discuss.gradle.org/t/how-to-remove-a-prefix-from-the-archive-names-for-all-subprojects/12918/1 "2015-11-24T12:55:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [November 24, 2015, 3:39pm UTC](https://discuss.gradle.org/t/how-to-remove-a-prefix-from-the-archive-names-for-all-subprojects/12918/2 "2015-11-24T15:39:46Z")

</div>

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](https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:archivesBaseName)

e.g., something like:

```gradle
subprojects {
   archivesBaseName = project.name - 'eventos-'
}

```

---

<div class="post-metadata">

**Author:** ![marcos\_aps](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@marcos\_aps](https://discuss.gradle.org/u/marcos_aps)\
**Post date:** [November 24, 2015, 3:54pm UTC](https://discuss.gradle.org/t/how-to-remove-a-prefix-from-the-archive-names-for-all-subprojects/12918/3 "2015-11-24T15:54:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![marcos\_aps](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@marcos\_aps](https://discuss.gradle.org/u/marcos_aps)\
**Post date:** [November 24, 2015, 5:35pm UTC](https://discuss.gradle.org/t/how-to-remove-a-prefix-from-the-archive-names-for-all-subprojects/12918/4 "2015-11-24T17:35:21Z")

</div>

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-"
	}	
}
```

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [November 24, 2015, 8:40pm UTC](https://discuss.gradle.org/t/how-to-remove-a-prefix-from-the-archive-names-for-all-subprojects/12918/5 "2015-11-24T20:40:59Z")

</div>

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-"
    }
}
```

---

<div class="post-metadata">

**Author:** ![marcos\_aps](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@marcos\_aps](https://discuss.gradle.org/u/marcos_aps)\
**Post date:** [November 25, 2015, 11:37am UTC](https://discuss.gradle.org/t/how-to-remove-a-prefix-from-the-archive-names-for-all-subprojects/12918/6 "2015-11-25T11:37:15Z")

</div>

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.
