# Java Project use existing MANIFEST not override

**URL:** <https://discuss.gradle.org/t/java-project-use-existing-manifest-not-override/32300>\
**Category:** Help/Discuss\
**Created:** [July 4, 2019, 8:17pm UTC](https://discuss.gradle.org/t/java-project-use-existing-manifest-not-override/32300 "2019-07-04T20:17:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![htourne](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@htourne](https://discuss.gradle.org/u/htourne)\
**Post date:** [July 4, 2019, 8:17pm UTC](https://discuss.gradle.org/t/java-project-use-existing-manifest-not-override/32300/1 "2019-07-04T20:17:54Z")

</div>

Hi, I have a problem with gradle, since it is generating the manifest although I have code to verify if it exists and not overwrite it.

Example:  
manifest {  
def manif = “${projectDir}/ejbModule/META-INF/MANIFEST.MF”  
if (new File(manif).exists()) {  
from file(manif)  
} else {  
println “$project.name no tiene el archivo $manif, se crea uno nuevo”  
manifest.attributes project: project.name  
manifest.attributes Build: new Date()  
}  
}

Thanks!

---

<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:** [July 6, 2019, 3:17am UTC](https://discuss.gradle.org/t/java-project-use-existing-manifest-not-override/32300/2 "2019-07-06T03:17:43Z")

</div>

What’s the context of where this `manifest { ... }` code block exists in your build script? If it’s not inside the configuration for a particular `Jar` task and you don’t apply this configuration to your `Jar` tasks, this is essentially a no-op.

---

<div class="post-metadata">

**Author:** ![htourne](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@htourne](https://discuss.gradle.org/u/htourne)\
**Post date:** [July 7, 2019, 2:34pm UTC](https://discuss.gradle.org/t/java-project-use-existing-manifest-not-override/32300/3 "2019-07-07T14:34:42Z")

</div>

Thanks for the response, the context is as follows:  
subprojects {  
…  
jar {  
manifest {  
def manif = “${projectDir}/src/META-INF/MANIFEST.MF”  
if (new File(manif).exists()) {  
from file(manif)  
} else {  
…  
}  
}

And also I have this:

project(’:GCOBRGUService’) {  
apply plugin: ‘war’

```
webAppDirName = file('WebContent') 
war {
	manifest {
  		def manif = "${projectDir}/WebContent/META-INF/MANIFEST.MF"
		if (new File(manif).exists()) {
   			from file(manif)
     	} else {
  			println "$project.name no tiene el archivo $manif, se crea uno nuevo"
   			manifest.attributes project: project.name
   			manifest.attributes Build: new Date()
  		}
 	}
}
dependencies {
	compileOnly project(':RADJPkg')
	compileOnly project(':RegularizacionesEJB3')
	compileOnly project(':RADInterfaceSolver')
	compileOnly name: 'common.performancelogger'
	compileOnly name: 'common.service'
}

```

}

---

<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:** [July 7, 2019, 11:54pm UTC](https://discuss.gradle.org/t/java-project-use-existing-manifest-not-override/32300/4 "2019-07-07T23:54:18Z")

</div>

Is the manifest in the root directory, or in each subproject? There’s discrepancies in the paths between your posts, so I’m not sure which values are reality. If I place the file in the exact location specified by the version of the code I’m using, I see the manifest file being used without a new being generated. I would expect that the location of the file vs. where you’re looking for it in your project don’t actually match up, but without a self-contained reproducible example project, it’s hard to say for sure.

---

<div class="post-metadata">

**Author:** ![htourne](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@htourne](https://discuss.gradle.org/u/htourne)\
**Post date:** [July 8, 2019, 12:23am UTC](https://discuss.gradle.org/t/java-project-use-existing-manifest-not-override/32300/5 "2019-07-08T00:23:33Z")

</div>

Sorry for the mixture of the codes.  
I’ll try to explain it better, first I have this in the subprojects section:

subprojects {  
//Put instructions for each sub project  
println “Compilando y empaquetando proyecto: $project.name”

```
apply plugin: 'java'

sourceCompatibility = '1.6'
targetCompatibility = '1.6'

sourceSets {
    main {
        java {
            srcDirs 'src'
            include '**/*.java'
        }
    }
}
	
jar {
	manifest {
  		def manif = "${projectDir}/src/META-INF/MANIFEST.MF"
		if (new File(manif).exists()) {
   			from file(manif)
     	} else {
  			def manifEjb = "${projectDir}/ejbModule/META-INF/MANIFEST.MF"
			if (new File(manifEjb).exists()) {
	   			from file(manifEjb)
	     	} else {
				def maniWeb ="${projectDir}/WebContent/META-INF/MANIFEST.MF"
				if(new File(maniWeb).exists()) {
					from file(maniWeb)
				}else{
					def maniRoot ="${projectDir}/META-INF/MANIFEST.MF"
					if(new File(maniRoot).exists()) {
						from file(maniRoot)
					}else{
						println "$project.name no tiene el archivo $manif"
						println "$project.name no tiene el archivo $manifEjb"
						println "$project.name no tiene el archivo $maniWeb"
						println "$project.name no tiene el archivo $maniRoot"
						println "No se encontro MANIFEST, se crea uno nuevo"
						manifest.attributes project: project.name
						manifest.attributes Build: new Date()
					}	  	
				}	  			
   			}
  		}
 	}
}

```

…  
}

What you try to do here is that for each project where you have a MANIFEST file, it is found, since depending on the project it is located in different places.

Then in the same build file, but in a war project for example I have this code too.

project(’:GCOBRGUService’) {  
apply plugin: ‘war’

```
webAppDirName = file('WebContent') 
war {
	manifest {
  		def manif = "${projectDir}/WebContent/META-INF/MANIFEST.MF"
		if (new File(manif).exists()) {
   			from file(manif)
     	} else {
  			println "$project.name no tiene el archivo $manif, se crea uno nuevo"
   			manifest.attributes project: project.name
   			manifest.attributes Build: new Date()
  		}
 	}
}

```

…  
}  
According to what you tell me, I understand that Gradle is not finding the MANIFEST that exists in the project, why does he generate one? because he can not find it? should I set the manifest statement in the subproject section or in the specific project?

Thanks!

---

<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:** [July 8, 2019, 2:30am UTC](https://discuss.gradle.org/t/java-project-use-existing-manifest-not-override/32300/6 "2019-07-08T02:30:39Z")

</div>

Gradle will always generate a `MANIFEST.MF` file to include in the JAR/WAR file. If you don’t customize it, it will be empty except for a line that specifies the manifest version: `Manifest-Version: 1.0`

In the code you’ve provided, the `MANIFEST.MF` is always customized, either using `from` or `attributes`. It adds the values in the file, if it exists, or it adds the project name and build date, which is what’s configured in the `else { ... }` block at the end. Note that both cases, it will write out a new manifest with either the file contents or the attributes specified. It will not just copy the file you provided exactly.

It really doesn’t matter if you configure the manifest in the `subprojects { ... }` block or in each project. They would be configuring the same thing, so it’s more of a personal style preference.

I’m not sure exactly what is happening in your project because I only have snippets, but based on you saying that Gradle is generating, I expect you’re seeing the output (with the values filled in) of:

```groovy
println "$project.name no tiene el archivo $manif"
println "$project.name no tiene el archivo $manifEjb"
println "$project.name no tiene el archivo $maniWeb"
println "$project.name no tiene el archivo $maniRoot"
println "No se encontro MANIFEST, se crea uno nuevo"

```

If that’s not the case, I still think your best option is to create the the smallest possible sharable project that recreates what you’re seeing (with just the manifest code shown above and some example `MANIFEST.MF` files in the locations you have them).

---

<div class="post-metadata">

**Author:** ![htourne](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@htourne](https://discuss.gradle.org/u/htourne)\
**Post date:** [July 8, 2019, 1:59pm UTC](https://discuss.gradle.org/t/java-project-use-existing-manifest-not-override/32300/7 "2019-07-08T13:59:24Z")

</div>

Hi, then there is no way that gradle does not generate the manifest and package the one that exists.  
The problem that I am having is that in the manifest that generates the names of the references they are cut and that causes me problems in the application.

Example of the manifest generated with gradle:

Manifest-Version: 1.0  
Class-Path: bps.common.security.entities.jar common.providers.jar wsRe  
gAportacionProxy.jar wsRegContribuyenteProxy.jar wsRegECAProxy.jar ws  
RegObraEmpresaConstruccionProxy.jar wsRegObraProxy.jar bps.common.uti  
l.jar bps.common.globalEntities.jar common.dao.jar wsRegCabezalProxy.  
jar wsRegCrossCabezalProxy.jar WsRegLocalBPSServiceProxy.jar WsRegEmp  
resasServiceProxy.jar WsRegUtilitariosServiceProxy.jar WsEmpresasCand  
idatasServiceProxy.jar WsNovedadesGCOBProxy.jar WsAdeudosServiceProxy  
.jar EntidadesRegEmp.jar bps.common.business.jar bps.common.dao.jar c  
ommon.db.jar RegularizacionesGenerico.jar WsGuiaGdtServiceProxy.jar E  
ntidadesGDT.jar CuentaEmpresaServicioDesmarcaDataTypes.jar CuentaEmpr  
esaServiciosEJB3Client.jar common.contract.jar common.contract.ejb.ja  
r common.performancelogger.jar WsActualizarDeudaServiceProxy.jar Enti  
dadesCalculos.jar WsGVJProxy.jar

Thanks

---

<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:** [July 9, 2019, 2:32am UTC](https://discuss.gradle.org/t/java-project-use-existing-manifest-not-override/32300/8 "2019-07-09T02:32:33Z")

</div>

What problems are you having? This is a valid manifest file. The manifest _should_ wrap lines, even in the middle of a file name. The Jar manifest specification requires that the lines are wrapped like this.

---

<div class="post-metadata">

**Author:** ![htourne](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@htourne](https://discuss.gradle.org/u/htourne)\
**Post date:** [July 9, 2019, 1:19pm UTC](https://discuss.gradle.org/t/java-project-use-existing-manifest-not-override/32300/9 "2019-07-09T13:19:32Z")

</div>

Hello, the problem I’m having with the manifest is the following, when I install the ear in websphere 7, it gives me this error:

Checking for application Regularizaciones

Application “Regularizaciones” is already installed!

stoping Regularizaciones on server server1 in node bpdesa1Node11.

Full Application Name ==\> [“Regularizaciones”]

Regularizaciones is already stoped on server server1 in node bpdesa1Node11

Checking for application Regularizaciones

Application “Regularizaciones” is already installed!

starting Regularizaciones on server server1 in node bpdesa1Node11.

Full Application Name ==\> [“Regularizaciones”]

WASX7017E: Exception received while running file “/local/urbancode/var/work/Regularizaciones\_Binaries/c8430c05-45c5-424e-9f0f-2ffeee2ae1d4.py”; exception information: javax.management.MBeanException

com.ibm.ws.exception.RuntimeWarning

com.ibm.ws.metadata.MetaDataException: com.ibm.ws.metadata.MetaDataException: CNTR0146E: The META-INF/ibm-ejb-jar-bnd.xml bindings file contained in the RegularizacionesEJB3.jar module has a configuration error at line number: 26, column number: 66.

Then I tried to replace the manifest of the project in question, with the manifest that I had in eclipse and the application started to work, that is why I began to investigate how to do so that gradle does not replace the manifest.

Thanks.
