lgrignon/jsweet-maven-plugin

'factoryClassPath' Option Does Not Work for Custom Factory

Closed this issue · 11 comments

Currently, the 'factoryClassPath' option in configuration only works for classes in jars included as dependencies of the jsweet-maven-plugin. If a custom JSweetFactory is defined within the project we are generating sources for, the generation will fail with a "cannot find or instantiate factory class" error.

Could you please link a github with an example of your case please. I will fix it soon

Here is the git: https://github.com/pbtura/bigjsExample
The custom factory is in the 'util' package.

Thanks. Indeed this is not possible since your class isn't compiled yet (at generate-sources time). I do not think this is standard in the Maven world to load class from the target project in a plugin mojo. I would recommend packaging your factory in an external JAR unless you recommend something better for loading project classes in the JSweet mojo.
However I agree that it would be very nice & straightforward to have this working.

Please tell me you thoughts or close issue if you don't think to a suggestion about it.

I see what you mean about not having the compiled factory class. If that is the only obstacle however, there is a way around it. By adding an execution to the maven-compiler-plugin, we can force it to compile the factory class before the generator plugin is run. So for the example I posted you would have something like this:

<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<fork>true</fork>
					<includes>
						<include>**/util/TuraJSweetFactory.java</include>
					</includes>
				</configuration>
				<executions>
					<execution>
						<id>generate-factory</id>
						<phase>generate-sources</phase>
						<goals>
							<goal>compile</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

As long as the maven-compiler plugin is placed before the generator plugin, and as long as both target the same phase (generate-sources) then the factory will be compiled and ready by the time it is needed in the plugin.

This seems kind of hacky to me but we could make this work indeed. Do you want to give it a try and PR? I won't have time this week-end for this :/

I'm currently tied up with other projects. Hopefully I will be able to do some more work on this in a week or two.

I finally got a chance to do some work on this and I think I have come up with a workable solution. I added a PR here: #42. Take a look when you get a chance and let me know what you think.

Fixed, thanks to PR #42

Thanks a lot to @pbtura

I tried to transpile https://github.com/pbtura/bigjsExample/blob/maven-plugin-demo/pom.xml
and
https://github.com/cincheo/jsweet-examples.git

Did you try cleaning your local repo (at least for org.jsweet group)

I tried that with no luck. I posted a bug report here: #43 with more details.