Skip to content

Problem With Autogenerated grails.factories #10238

@jeffscottbrown

Description

@jeffscottbrown

The following is happening with Grails 3.1.12.

See project at https://github.com/jeffbrown/factories-problem.

src/main/resources/META-INF/services/grails.factories:

org.grails.taglib.encoder.OutputContextLookup=problem.FooOutputContextLookup

src/main/groovy/problem/SpecialService.groovy

package problem

import grails.artefact.Enhances

@Enhances('Service')
trait SpecialService {
}

If grails.factories doesn't exist, GlobalGrailsClassInjectorTransformation is supposed to generate a new one that looks like this:

grails.compiler.traits.TraitInjector=problem.SpecialServiceTraitInjector

If one does exist, instead of creating a new one, the existing one is supposed to be updated with the reference to problem.SpecialServiceTraitInjector.

A problem exists right now in that the compiler is looking to see if a new one exists at build/classes/main/META-INF/grails.factories but it actually exists at build/resources/main/META-INF/services/grails.factories. This results in the system creating a new one instead of appending to the existing one.

In the project linked above run ./gradlew clean jar. That will result in the following:

factories-problem master $ cat build/classes/main/META-INF/grails.factories 
#Grails Factories File
#Tue Oct 18 19:21:39 CDT 2016
grails.compiler.traits.TraitInjector=problem.SpecialServiceTraitInjector
factories-problem master $ 
factories-problem master $ cat build/resources/main/META-INF/services/grails.factories 
org.grails.taglib.encoder.OutputContextLookup=problem.FooOutputContextLookup

The META-INF/services/grails.factories that is added to build/libs/factories-problem-0.1.jar looks like this:

org.grails.taglib.encoder.OutputContextLookup=problem.FooOutputContextLookup

I think the problem is at https://github.com/grails/grails-core/blob/991ef0074b2eecfabaf4c770084ebb9bb1bfcd64/grails-core/src/main/groovy/org/grails/compiler/injection/GlobalGrailsClassInjectorTransformation.groovy#L146. source.configuration.targetDirectory evaluates to build/classes/main.

The net effect is that if a plugin provides a trait marked with @Enhances and the plugin also happens to contain a grails.factories file, the @Enhances won't work because the grails.factories won't contain the necessary metadata. A workaround is to put the metadata in the existing grails.factories by hand.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions