Java Project use existing MANIFEST not override

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!

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.

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'
}

}

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.

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!

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:

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).

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

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.

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.