You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Saravanan Palanichamy <ch...@gmail.com> on 2025/06/09 07:21:37 UTC
Controlled compilation
Hello Groovy devs
I am trying to understand how to do this with the Groovy Compiler
- I have say 20 files in my project
- I know I have to compile just one of those files
- This one file imports other files (maybe 3 and those 3 import another
2 lets say). But not all 20 files are used
- Lets assume I dont do any reflection and everything is defined
explicitly
How do I get the compiler to just compile the files that are needed and
leave out the ones that are not needed. Essentially tree-shaking.
regards
Saravanan
Re: Controlled compilation
Posted by MG <mg...@arscreat.com>.
Hi Saravanan,
could you just use union mounts / bind mounts under Linux, to combine
all the source directories as to appear as one ?
Cheers,
mg
Am 09.06.2025 um 20:26 schrieb Saravanan Palanichamy:
> Thank you Eric
>
> I dont know if I want incremental compilation. I'll state the problem
> differently
>
> * I have a file to compile. It imports a bunch of other files and types
> * I want to start compiling this file and as the resolver is kicking
> in, I want to give the compiler additional files to add to the
> list (and recurse on any dependencies from this new list as well)
>
> regards
> Saravanan
>
> On Mon, Jun 9, 2025 at 9:47 AM Milles, Eric (TR Technology) via dev
> <de...@groovy.apache.org> wrote:
>
> I think what you are describing is "incremental compilation".
>
> There are open issue items about incremental compilation:
> * https://issues.apache.org/jira/browse/GROOVY-11666
> * https://issues.apache.org/jira/browse/GROOVY-10932
>
> This feature is not mentioned in the docs for groovyc.
> https://groovy-lang.org/groovyc.html
>
> I don't think there is explicit support to provide all sources and
> a partially populated binary directory and have the compiler work
> out just what to build. Maven might provide some of this on top
> of groovyc. Incremental is indicated as on by default since Maven
> 3.1:
> https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#useIncrementalCompilation
>
>
> ------------------------------------------------------------------------
> *From:* Saravanan Palanichamy <ch...@gmail.com>
> *Sent:* Monday, June 9, 2025 11:01 AM
> *To:* dev@groovy.apache.org <de...@groovy.apache.org>
> *Subject:* [EXT] Re: Controlled compilation
> *External Email:* Use caution with links and attachments.
>
>
> Thank you Jochen for your reply
>
> some followup
>
> * My source files may be in different locations (I want to say
> here's three different source directories, they form the
> source closure. But compile only foo.groovy and let the
> compiler decide what other files in what locations need to be
> pulled up for the compile). I saw that groovyc is backed by
> FileSystemCompiler.java and it is doing the same thing I am
> doing I think (it adds all source files passed in the command
> line args to the compile unit). What's the way to pass in only
> foo.groovy but then say here are other source units/files one
> of which is bar.groovy, just use the ones you need and leave
> out the others
>
> If it helps,
>
> * I assume every file will only have one class defined (these
> are java files that are being compiled with the Groovy
> compiler, so java limitations will help)
> * I can also do multi pass compiles, time to compile is not a
> limitation
>
> regards
> Saravanan
>
> On Mon, Jun 9, 2025 at 4:21 AM Jochen Theodorou
> <bl...@gmx.org> wrote:
>
> On 09.06.25 09:21, Saravanan Palanichamy wrote:
> > Hello Groovy devs
> >
> > I am trying to understand how to do this with the Groovy
> Compiler
> >
> > * I have say 20 files in my project
> > * I know I have to compile just one of those files
>
> groovyc foo.groovy
>
> will compile foo.groovy and potentially its dependencies. A
> dependency
> should be compiled filed in class format, or source file. If
> both are
> available then which is newer decide if recompilation happens.
> If a
> dependency is not found compilation will fail.
>
> bye Jochen
>
Re: Controlled compilation
Posted by Saravanan Palanichamy <ch...@gmail.com>.
Thank you Eric
I dont know if I want incremental compilation. I'll state the problem
differently
- I have a file to compile. It imports a bunch of other files and types
- I want to start compiling this file and as the resolver is kicking in,
I want to give the compiler additional files to add to the list (and
recurse on any dependencies from this new list as well)
regards
Saravanan
On Mon, Jun 9, 2025 at 9:47 AM Milles, Eric (TR Technology) via dev <
dev@groovy.apache.org> wrote:
> I think what you are describing is "incremental compilation".
>
> There are open issue items about incremental compilation:
> * https://issues.apache.org/jira/browse/GROOVY-11666
> * https://issues.apache.org/jira/browse/GROOVY-10932
>
> This feature is not mentioned in the docs for groovyc.
> https://groovy-lang.org/groovyc.html
>
> I don't think there is explicit support to provide all sources and a
> partially populated binary directory and have the compiler work out just
> what to build. Maven might provide some of this on top of groovyc.
> Incremental is indicated as on by default since Maven 3.1:
> https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#useIncrementalCompilation
>
>
> ------------------------------
> *From:* Saravanan Palanichamy <ch...@gmail.com>
> *Sent:* Monday, June 9, 2025 11:01 AM
> *To:* dev@groovy.apache.org <de...@groovy.apache.org>
> *Subject:* [EXT] Re: Controlled compilation
>
> *External Email:* Use caution with links and attachments.
>
> Thank you Jochen for your reply
>
> some followup
>
> - My source files may be in different locations (I want to say here's
> three different source directories, they form the source closure. But
> compile only foo.groovy and let the compiler decide what other files in
> what locations need to be pulled up for the compile). I saw that groovyc is
> backed by FileSystemCompiler.java and it is doing the same thing I am doing
> I think (it adds all source files passed in the command line args to the
> compile unit). What's the way to pass in only foo.groovy but then say here
> are other source units/files one of which is bar.groovy, just use the ones
> you need and leave out the others
>
> If it helps,
>
> - I assume every file will only have one class defined (these are java
> files that are being compiled with the Groovy compiler, so java limitations
> will help)
> - I can also do multi pass compiles, time to compile is not a
> limitation
>
> regards
> Saravanan
>
> On Mon, Jun 9, 2025 at 4:21 AM Jochen Theodorou <bl...@gmx.org> wrote:
>
> On 09.06.25 09:21, Saravanan Palanichamy wrote:
> > Hello Groovy devs
> >
> > I am trying to understand how to do this with the Groovy Compiler
> >
> > * I have say 20 files in my project
> > * I know I have to compile just one of those files
>
> groovyc foo.groovy
>
> will compile foo.groovy and potentially its dependencies. A dependency
> should be compiled filed in class format, or source file. If both are
> available then which is newer decide if recompilation happens. If a
> dependency is not found compilation will fail.
>
> bye Jochen
>
>
Re: Controlled compilation
Posted by "Milles, Eric (TR Technology) via dev" <de...@groovy.apache.org>.
I think what you are describing is "incremental compilation".
There are open issue items about incremental compilation:
* https://issues.apache.org/jira/browse/GROOVY-11666
* https://issues.apache.org/jira/browse/GROOVY-10932
This feature is not mentioned in the docs for groovyc. https://groovy-lang.org/groovyc.html
I don't think there is explicit support to provide all sources and a partially populated binary directory and have the compiler work out just what to build. Maven might provide some of this on top of groovyc. Incremental is indicated as on by default since Maven 3.1: https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#useIncrementalCompilation
________________________________
From: Saravanan Palanichamy <ch...@gmail.com>
Sent: Monday, June 9, 2025 11:01 AM
To: dev@groovy.apache.org <de...@groovy.apache.org>
Subject: [EXT] Re: Controlled compilation
External Email: Use caution with links and attachments.
Thank you Jochen for your reply
some followup
* My source files may be in different locations (I want to say here's three different source directories, they form the source closure. But compile only foo.groovy and let the compiler decide what other files in what locations need to be pulled up for the compile). I saw that groovyc is backed by FileSystemCompiler.java and it is doing the same thing I am doing I think (it adds all source files passed in the command line args to the compile unit). What's the way to pass in only foo.groovy but then say here are other source units/files one of which is bar.groovy, just use the ones you need and leave out the others
If it helps,
* I assume every file will only have one class defined (these are java files that are being compiled with the Groovy compiler, so java limitations will help)
* I can also do multi pass compiles, time to compile is not a limitation
regards
Saravanan
On Mon, Jun 9, 2025 at 4:21 AM Jochen Theodorou <bl...@gmx.org>> wrote:
On 09.06.25 09:21, Saravanan Palanichamy wrote:
> Hello Groovy devs
>
> I am trying to understand how to do this with the Groovy Compiler
>
> * I have say 20 files in my project
> * I know I have to compile just one of those files
groovyc foo.groovy
will compile foo.groovy and potentially its dependencies. A dependency
should be compiled filed in class format, or source file. If both are
available then which is newer decide if recompilation happens. If a
dependency is not found compilation will fail.
bye Jochen
Re: Controlled compilation
Posted by OCsite <oc...@ocs.cz>.
Given a Groovy source can contain any number of classes with any names, the detection that ABC depends on a given source DEF is going to be rather at the difficult side.
The only solution I can see is to build all the sources at start and use appropriate ASTTs to create a complete map source <-> classes. This map then
(a) could be used to decide which sources to mark dirty and send them to the compiler upon a rebuild
(b) could be just as well used to find the source which generates a given class, referred from another one
(c) would, of course, have to be updated whenever a source changes and thus could refer/generate different classes than before.
Perhaps ther's a better solution which I am overlooking, of course.
All the best,
OC
> On 10. 6. 2025, at 15:15, Saravanan Palanichamy <ch...@gmail.com> wrote:
>
> Hi Jochen
>
> Thank you for the explanation. I am not trying to do this with a build system like gradle or make. I am hosting the Groovy Compiler in a Java CLI and I have my own customizations. This is my setup
>
> A Java CLI that bundles the Groovy Compiler and takes command like options to feed to CompilerConfiguration
> I use the CompilationUnit to add all my sources and compile in one shot
> My source code is split across multiple libraries. I start with a code base in package A, that will include package B and C, each of which is a separate folder. So in a sense I am trying to compile all packages together in one go.
> What I want to do
> I know a file ABC.java contains a function of interest
> I want to compile just that class ABC, even though I have the complete code closure of everything
> As I compile ABC, I want to detect that it depends on DEF.java and I want to give the compiler DEF. As it compiles DEF, it may pull in XYZ.java, I want to hand that over. And so on
> The goal is to produce bytecode only for ABC and all its dependencies. Some things I thought of
>
> Add ABC.java as the only source unit. Then I override resolve visitor, to detect all resolve attempts. I now know what other classes need to be resolved, so I try to add new files to the compilation units. The code looks like it should go back to initialization phase. Now when I see other classes that I added, I can repeat this process recursively. I am not sure how feasible this is given the amount of looping back and forth
> Your comment about allowing groovy to find the script file was interesting. So run GroovyC on one file and let the compile find all dependencies as scripts. This looks like exactly what I want to do in 1. but all my files are named .java so I am not sure groovy will find them
> Which approach do you think I should try?
>
> regards
> Saravanan
>
>
> On Mon, Jun 9, 2025 at 11:28 AM Jochen Theodorou <blackdrag@gmx.org <ma...@gmx.org>> wrote:
>> On 09.06.25 18:01, Saravanan Palanichamy wrote:
>> > Thank you Jochen for your reply
>> >
>> > some followup
>> >
>> > * My source files may be in different locations (I want to say here's
>> > three different source directories, they form the source closure.
>> > But compile only foo.groovy and let the compiler decide what other
>> > files in what locations need to be pulled up for the compile). I saw
>> > that groovyc is backed by FileSystemCompiler.java and it is doing
>> > the same thing I am doing I think (it adds all source files passed
>> > in the command line args to the compile unit). What's the way to
>> > pass in only foo.groovy but then say here are other source
>> > units/files one of which is bar.groovy, just use the ones you need
>> > and leave out the others
>>
>> I think that case is not well supported right now. What you can try is
>> giving groovyc a classpath and put each source path in there, then just
>> do the compilation with the single file. The compiler should detect the
>> source files in the class path
>>
>> well.. used to... we had no tests in that direction so maybe this
>> mechanism does no longer work. We also used to have sourcepath. But
>> that would have been for a single directory, you need multiple and well,
>> it got deprecated anyway
>>
>> > If it helps,
>> >
>> > * I assume every file will only have one class defined (these are java
>> > files that are being compiled with the Groovy compiler, so java
>> > limitations will help)
>> > * I can also do multi pass compiles, time to compile is not a limitation
>>
>>
>> If you want to make this with "make" you could write a make file and
>> make tells you what sources changed (based on the class files) and then
>> you could just pass the compiles class files on the classpath and the
>> changed source files to the compiler. Of course make is kind of archaic.
>>
>> But you could consider a build system
>>
>> bye Jochen
>>
Re: Controlled compilation
Posted by Saravanan Palanichamy <ch...@gmail.com>.
Hi Jochen
> The compile error is that a class gets left behind in the
> CompileUnit's classesToCompile. I think this is because I am returning a
> source unit that contains both outer and inner classes when the look up
> should have returned an inner class. What is the right way to fix this?
> Should I add the source unit but return a dummy classnode that is not
> resolved yet?
This works great for classes without generic types. But for classes with
generic types, if I return a ClassHelper.make(theName) through
LookupResults(classNode, null), then I get this error for classes with
generic types
The class com.company.v2.shared.model.ImmutableKey.Builder<T> (supplied
> with 1 type parameter) refers to the class
> com.company.v2.shared.model.ImmutableKey.Builder which takes no parameters
How do I handle this?
regards
Saravanan
On Thu, Jun 12, 2025 at 10:51 AM Jochen Theodorou <bl...@gmx.org> wrote:
> On 12.06.25 16:07, Saravanan Palanichamy wrote:
> > Thank you Jochen,
> >
> > I made some progress based on your recommendations in this manner
> >
> > 1. Added one source file as source unit to the compilation unit
> > 2. I use a compilation unit that uses my custom ClassNodeResolver that
> > derives from the base ClassNodeResolver
> > 3. When it hits the findClassNode function, I call the parent, if the
> > parent returned null, I then look in my directory folder for the
> > file (I use the node name, replace the .'s with /'s and look for the
> > file in my source folders)
> > 4. And it works beautifully as it goes through resolving things for me
> >
> > Right now I feel like the kitten that unravelled the dependency string
> > ball.😃 , thank you very much for helping with this
>
> nice
>
> [...]
> > The compile error is that a class gets left behind in the
> > CompileUnit's classesToCompile. I think this is because I am returning a
> > source unit that contains both outer and inner classes when the look up
> > should have returned an inner class. What is the right way to fix this?
> > Should I add the source unit but return a dummy classnode that is not
> > resolved yet?
>
> yeah please try that.
>
> bye Jochen
>
Re: Controlled compilation
Posted by Jochen Theodorou <bl...@gmx.org>.
On 6/17/25 00:08, Saravanan Palanichamy wrote:
> Hi Jochen/Other devs
>
> Please ignore my previous email. I have narrowed down the problem. I
> will state what I am doing first
>
> 1. I have my own ClassNodeResolver that overrides findClassNode and
> finds source units that match the class being looked for. I return
> the sourceunit if the class name and the source unit names match
> (through LookUpResult(sourceUnit)) and I return a class node if I am
> looking for an inner class in the source unit (through
> LookUpResult(ClassHelper.makeWithoutCaching...))
ClassHelper.makeWithoutCaching is for precompiled classes.
> 2. This works up until the very end of Phase SEMANTIC_ANALYSIS
> 3. But when I exit that phase, I see that one source unit is still
> queued. Fortunately, this gets added back because of the dequeued()
> operation (in compilationunit.java) after every phase
> 4. But what ends up happening is that every other phase operation I
> added (all my compiler customizations) have now run twice (first
> before the dequeue operation because the interrupt exception was not
> thrown to stop further phase processing and then after that last
> class has been added back to the compile mix as part of the
> dequeued() call)
should the old source units not gotten into the new phase at this point
already? Unless you add the same twice the phase operations should run
only once for this unit, even with dequeue
bye Jochen
Re: Controlled compilation
Posted by Saravanan Palanichamy <ch...@gmail.com>.
Hi Jochen/Other devs
Please ignore my previous email. I have narrowed down the problem. I will
state what I am doing first
1. I have my own ClassNodeResolver that overrides findClassNode and
finds source units that match the class being looked for. I return the
sourceunit if the class name and the source unit names match (through
LookUpResult(sourceUnit)) and I return a class node if I am looking for an
inner class in the source unit (through
LookUpResult(ClassHelper.makeWithoutCaching...))
2. This works up until the very end of Phase SEMANTIC_ANALYSIS
3. But when I exit that phase, I see that one source unit is still
queued. Fortunately, this gets added back because of the dequeued()
operation (in compilationunit.java) after every phase
4. But what ends up happening is that every other phase operation I
added (all my compiler customizations) have now run twice (first before the
dequeue operation because the interrupt exception was not thrown to stop
further phase processing and then after that last class has been added back
to the compile mix as part of the dequeued() call)
How do I prevent this double processing of phase operations from happening?
regards
Saravanan
On Thu, Jun 12, 2025 at 11:21 PM Jochen Theodorou <bl...@gmx.org> wrote:
> On 12.06.25 16:07, Saravanan Palanichamy wrote:
> > Thank you Jochen,
> >
> > I made some progress based on your recommendations in this manner
> >
> > 1. Added one source file as source unit to the compilation unit
> > 2. I use a compilation unit that uses my custom ClassNodeResolver that
> > derives from the base ClassNodeResolver
> > 3. When it hits the findClassNode function, I call the parent, if the
> > parent returned null, I then look in my directory folder for the
> > file (I use the node name, replace the .'s with /'s and look for the
> > file in my source folders)
> > 4. And it works beautifully as it goes through resolving things for me
> >
> > Right now I feel like the kitten that unravelled the dependency string
> > ball.😃 , thank you very much for helping with this
>
> nice
>
> [...]
> > The compile error is that a class gets left behind in the
> > CompileUnit's classesToCompile. I think this is because I am returning a
> > source unit that contains both outer and inner classes when the look up
> > should have returned an inner class. What is the right way to fix this?
> > Should I add the source unit but return a dummy classnode that is not
> > resolved yet?
>
> yeah please try that.
>
> bye Jochen
>
Re: Controlled compilation
Posted by Jochen Theodorou <bl...@gmx.org>.
On 12.06.25 16:07, Saravanan Palanichamy wrote:
> Thank you Jochen,
>
> I made some progress based on your recommendations in this manner
>
> 1. Added one source file as source unit to the compilation unit
> 2. I use a compilation unit that uses my custom ClassNodeResolver that
> derives from the base ClassNodeResolver
> 3. When it hits the findClassNode function, I call the parent, if the
> parent returned null, I then look in my directory folder for the
> file (I use the node name, replace the .'s with /'s and look for the
> file in my source folders)
> 4. And it works beautifully as it goes through resolving things for me
>
> Right now I feel like the kitten that unravelled the dependency string
> ball.😃 , thank you very much for helping with this
nice
[...]
> The compile error is that a class gets left behind in the
> CompileUnit's classesToCompile. I think this is because I am returning a
> source unit that contains both outer and inner classes when the look up
> should have returned an inner class. What is the right way to fix this?
> Should I add the source unit but return a dummy classnode that is not
> resolved yet?
yeah please try that.
bye Jochen
Re: Controlled compilation
Posted by Saravanan Palanichamy <ch...@gmail.com>.
Thank you Jochen,
I made some progress based on your recommendations in this manner
1. Added one source file as source unit to the compilation unit
2. I use a compilation unit that uses my custom ClassNodeResolver that
derives from the base ClassNodeResolver
3. When it hits the findClassNode function, I call the parent, if the
parent returned null, I then look in my directory folder for the file (I
use the node name, replace the .'s with /'s and look for the file in my
source folders)
4. And it works beautifully as it goes through resolving things for me
Right now I feel like the kitten that unravelled the dependency string
ball.😃 , thank you very much for helping with this
But I ran into one snag. If the ClassNodeResolver is looking for a class
ABC.INNERDEF, then I am able to detect and resolve ABC and add that source
unit to the compilation process. However, this causes an issue with the
phased operations. This is my pseudo code
// If a class node was not found
> LookupResult MyClassNodeResolver.findClassNode(String name,
> CompilationUnit compilationUnit) {
> var parentResult = super.findClassNode(name, compilationUnit)
> if (parentResult == null) findInMyRepository(name, compilationUnit)
> }
>
> LookupResult findInMyRespository(name, ...) {
>
> // Find name or a substring of name in my folders (I search for
> "." increments)
> // If whole name or partial name found, return that result
> var sourceUnit = new SourceUnit(fileFound, ...)
> compilationUnit.addSource(sourceUnit)
> return LookupResult(sourceUnit, null)
> }
The compile error is that a class gets left behind in the
CompileUnit's classesToCompile. I think this is because I am returning a
source unit that contains both outer and inner classes when the look up
should have returned an inner class. What is the right way to fix this?
Should I add the source unit but return a dummy classnode that is not
resolved yet?
regards
Saravanan
On Tue, Jun 10, 2025 at 8:59 AM Jochen Theodorou <bl...@gmx.org> wrote:
> On 10.06.25 15:15, Saravanan Palanichamy wrote:
> [...]
> > 1. Add ABC.java as the only source unit. Then I override resolve
> > visitor, to detect all resolve attempts. I now know what other
> > classes need to be resolved, so I try to add new files to the
> > compilation units. The code looks like it should go back to
> > initialization phase. Now when I see other classes that I added, I
> > can repeat this process recursively. I am not sure how feasible this
> > is given the amount of looping back and forth
>
> that is perfectly fine.
>
> > 2. Your comment about allowing groovy to find the script file was
> > interesting. So run GroovyC on one file and let the compile find all
> > dependencies as scripts. This looks like exactly what I want to do
> > in 1. but all my files are named .java so I am not sure groovy will
> > find them
>
> didn't we have an option to set the extension of the files in the
> compiler configuration?
>
> > Which approach do you think I should try?
>
> the later one looks promising. Don't worry about resolving the same file
> multiple times. Resolved types will stay resolved and skipped if the
> resolver revisits them. Also not the whole compiler goes back to init,
> just for the specific source unit. Once all source units are at the same
> progress level they proceed together again.
>
> bye Jochen
>
>
Re: Controlled compilation
Posted by Jochen Theodorou <bl...@gmx.org>.
On 10.06.25 15:15, Saravanan Palanichamy wrote:
[...]
> 1. Add ABC.java as the only source unit. Then I override resolve
> visitor, to detect all resolve attempts. I now know what other
> classes need to be resolved, so I try to add new files to the
> compilation units. The code looks like it should go back to
> initialization phase. Now when I see other classes that I added, I
> can repeat this process recursively. I am not sure how feasible this
> is given the amount of looping back and forth
that is perfectly fine.
> 2. Your comment about allowing groovy to find the script file was
> interesting. So run GroovyC on one file and let the compile find all
> dependencies as scripts. This looks like exactly what I want to do
> in 1. but all my files are named .java so I am not sure groovy will
> find them
didn't we have an option to set the extension of the files in the
compiler configuration?
> Which approach do you think I should try?
the later one looks promising. Don't worry about resolving the same file
multiple times. Resolved types will stay resolved and skipped if the
resolver revisits them. Also not the whole compiler goes back to init,
just for the specific source unit. Once all source units are at the same
progress level they proceed together again.
bye Jochen
Re: Controlled compilation
Posted by Saravanan Palanichamy <ch...@gmail.com>.
Hi Jochen
Thank you for the explanation. I am not trying to do this with a build
system like gradle or make. I am hosting the Groovy Compiler in a Java CLI
and I have my own customizations. This is my setup
- A Java CLI that bundles the Groovy Compiler and takes command like
options to feed to CompilerConfiguration
- I use the CompilationUnit to add all my sources and compile in one shot
- My source code is split across multiple libraries. I start with a code
base in package A, that will include package B and C, each of which is a
separate folder. So in a sense I am trying to compile all packages together
in one go.
What I want to do
- I know a file ABC.java contains a function of interest
- I want to compile just that class ABC, even though I have the complete
code closure of everything
- As I compile ABC, I want to detect that it depends on DEF.java and I
want to give the compiler DEF. As it compiles DEF, it may pull in XYZ.java,
I want to hand that over. And so on
The goal is to produce bytecode only for ABC and all its dependencies. Some
things I thought of
1. Add ABC.java as the only source unit. Then I override resolve
visitor, to detect all resolve attempts. I now know what other classes need
to be resolved, so I try to add new files to the compilation units. The
code looks like it should go back to initialization phase. Now when I see
other classes that I added, I can repeat this process recursively. I am not
sure how feasible this is given the amount of looping back and forth
2. Your comment about allowing groovy to find the script file was
interesting. So run GroovyC on one file and let the compile find all
dependencies as scripts. This looks like exactly what I want to do in 1.
but all my files are named .java so I am not sure groovy will find them
Which approach do you think I should try?
regards
Saravanan
On Mon, Jun 9, 2025 at 11:28 AM Jochen Theodorou <bl...@gmx.org> wrote:
> On 09.06.25 18:01, Saravanan Palanichamy wrote:
> > Thank you Jochen for your reply
> >
> > some followup
> >
> > * My source files may be in different locations (I want to say here's
> > three different source directories, they form the source closure.
> > But compile only foo.groovy and let the compiler decide what other
> > files in what locations need to be pulled up for the compile). I saw
> > that groovyc is backed by FileSystemCompiler.java and it is doing
> > the same thing I am doing I think (it adds all source files passed
> > in the command line args to the compile unit). What's the way to
> > pass in only foo.groovy but then say here are other source
> > units/files one of which is bar.groovy, just use the ones you need
> > and leave out the others
>
> I think that case is not well supported right now. What you can try is
> giving groovyc a classpath and put each source path in there, then just
> do the compilation with the single file. The compiler should detect the
> source files in the class path
>
> well.. used to... we had no tests in that direction so maybe this
> mechanism does no longer work. We also used to have sourcepath. But
> that would have been for a single directory, you need multiple and well,
> it got deprecated anyway
>
> > If it helps,
> >
> > * I assume every file will only have one class defined (these are java
> > files that are being compiled with the Groovy compiler, so java
> > limitations will help)
> > * I can also do multi pass compiles, time to compile is not a
> limitation
>
>
> If you want to make this with "make" you could write a make file and
> make tells you what sources changed (based on the class files) and then
> you could just pass the compiles class files on the classpath and the
> changed source files to the compiler. Of course make is kind of archaic.
>
> But you could consider a build system
>
> bye Jochen
>
>
Re: Controlled compilation
Posted by Jochen Theodorou <bl...@gmx.org>.
On 09.06.25 18:01, Saravanan Palanichamy wrote:
> Thank you Jochen for your reply
>
> some followup
>
> * My source files may be in different locations (I want to say here's
> three different source directories, they form the source closure.
> But compile only foo.groovy and let the compiler decide what other
> files in what locations need to be pulled up for the compile). I saw
> that groovyc is backed by FileSystemCompiler.java and it is doing
> the same thing I am doing I think (it adds all source files passed
> in the command line args to the compile unit). What's the way to
> pass in only foo.groovy but then say here are other source
> units/files one of which is bar.groovy, just use the ones you need
> and leave out the others
I think that case is not well supported right now. What you can try is
giving groovyc a classpath and put each source path in there, then just
do the compilation with the single file. The compiler should detect the
source files in the class path
well.. used to... we had no tests in that direction so maybe this
mechanism does no longer work. We also used to have sourcepath. But
that would have been for a single directory, you need multiple and well,
it got deprecated anyway
> If it helps,
>
> * I assume every file will only have one class defined (these are java
> files that are being compiled with the Groovy compiler, so java
> limitations will help)
> * I can also do multi pass compiles, time to compile is not a limitation
If you want to make this with "make" you could write a make file and
make tells you what sources changed (based on the class files) and then
you could just pass the compiles class files on the classpath and the
changed source files to the compiler. Of course make is kind of archaic.
But you could consider a build system
bye Jochen
Re: Controlled compilation
Posted by Saravanan Palanichamy <ch...@gmail.com>.
Thank you Jochen for your reply
some followup
- My source files may be in different locations (I want to say here's
three different source directories, they form the source closure. But
compile only foo.groovy and let the compiler decide what other files in
what locations need to be pulled up for the compile). I saw that groovyc is
backed by FileSystemCompiler.java and it is doing the same thing I am doing
I think (it adds all source files passed in the command line args to the
compile unit). What's the way to pass in only foo.groovy but then say here
are other source units/files one of which is bar.groovy, just use the ones
you need and leave out the others
If it helps,
- I assume every file will only have one class defined (these are java
files that are being compiled with the Groovy compiler, so java limitations
will help)
- I can also do multi pass compiles, time to compile is not a limitation
regards
Saravanan
On Mon, Jun 9, 2025 at 4:21 AM Jochen Theodorou <bl...@gmx.org> wrote:
> On 09.06.25 09:21, Saravanan Palanichamy wrote:
> > Hello Groovy devs
> >
> > I am trying to understand how to do this with the Groovy Compiler
> >
> > * I have say 20 files in my project
> > * I know I have to compile just one of those files
>
> groovyc foo.groovy
>
> will compile foo.groovy and potentially its dependencies. A dependency
> should be compiled filed in class format, or source file. If both are
> available then which is newer decide if recompilation happens. If a
> dependency is not found compilation will fail.
>
> bye Jochen
>
Re: Controlled compilation
Posted by Jochen Theodorou <bl...@gmx.org>.
On 09.06.25 09:21, Saravanan Palanichamy wrote:
> Hello Groovy devs
>
> I am trying to understand how to do this with the Groovy Compiler
>
> * I have say 20 files in my project
> * I know I have to compile just one of those files
groovyc foo.groovy
will compile foo.groovy and potentially its dependencies. A dependency
should be compiled filed in class format, or source file. If both are
available then which is newer decide if recompilation happens. If a
dependency is not found compilation will fail.
bye Jochen