4 ms·
can you show an example of how you'd parse, say, a .java.in file from Maven (say match some lines with regexes), and generate a .java file from it, that you'd a
by jcelerier 4y ago
can you show an example of how you'd parse, say, a .java.in file from Maven (say match some lines with regexes), and generate a .java file from it, that you'd add as part of the build? And could you really say that this would be cleaner than the same thing done with cmake?
- cogman10 4y ago> can you show an example of how you'd parse, say, a .java.in The canonical way to do such a thing is through the java annotation processing api [1] and using a tool like java poet [2]. Before you did that, you'd probably decide if you wanted to instead use bytecode generation with a library like bytebuddy [3] But, assuming for some reason, you wanted to torture yourself and actually consume a java.in file and apply a regex, then you'd probably pull out the "maven-replacer-plugin" [4] and configure that for the task at hand. (or use your favorite templating language plugin. There's a million of them). Though, to be fair, this really isn't something that comes up in regular java programming due to the nature of the ecosystem. Anything you'd want to codegen likely already has a library and anything you didn't would receive (legitimate) push back. > And could you really say that this would be cleaner than the same thing done with cmake? Probably not. But not really the main point. cmake becomes a problem when you want to do anything more complex than string replacement. Imagine, for example, if you did want to use a code generation library within a project. The strength of maven is a new team dev only needs maven. Further, if they need to update that library they only need to change that maven file. What happens with cmake if you wanted to update a minimum dependency? [1] https://www.baeldung.com/java-annotation-processing-builder https://www.baeldung.com/java-annotation-processing-builder [2] https://github.com/square/javapoet https://github.com/square/javapoet [3] https://bytebuddy.net/ https://bytebuddy.net/ [4] https://github.com/beiliubei/maven-replacer-plugin https://github.com/beiliubei/maven-replacer-plugin
- jcelerier 4y agoI just don't understand in which universe having to look for X plug-ins which may or may not be maintained (the first I looked at had its last update in 2015) is better than cmake ; cmakelang could be literally a befunge variant of INTERCAL than it'd still be a better choice than this for me