You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Jacob Beard <jb...@cs.mcgill.ca> on 2010/08/25 17:05:03 UTC

Maven build for compiling JavaScript project

Hi,

I'm working on a Commons sandbox component which is written mostly in 
JavaScript. I currently have an ant build which includes tasks to do the 
following:

1. combine all of the JavaScript modules into a single file
2. minify the combined JavaScript file using the Google Closure 
JavaScript compiler
3. compile the combined JavaScript file to a single Java class file 
using the Rhino jsc compiler
4. create an executable JAR containing the class file.

I'm interested in working toward releasing the project, and so I'm 
trying to determine what would be the most elegant way to now build this 
project with Maven. Based on my understanding of the tasks performed by 
Maven when staging a release, it seems to me that the compiler task 
would need to be made to delegate to tasks 1-3 of the project's Ant 
script. After the class file has been created with jsc, I believe the 
Maven jar and assembly tasks should work as though the project were a 
regular Java project.

If my understanding so far is correct, I'm wondering what is the best 
way to override or customize the behaviour of Maven's compiler task so 
that it delegates to Ant (probably via the antrun Maven plugin)?

I'd appreciate any guidance anyone can provide. Thanks,

Jake

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Maven build for compiling JavaScript project

Posted by Jacob Beard <jb...@cs.mcgill.ca>.
Hi Manos,

Reply below:

On 10-08-26 11:01 AM, Manos Batsis wrote:
>  - Introduce new ant targets without the dependencies to call in each 
> appropriate Maven phase, thus preserving the old targets and the Ant 
> build behavior to be used if needed and when not working with Maven
This one sounds like a winner. With a little bit of work introducing 
Maven-specific tasks, it should be possible to make the script callable 
directly with Ant, or from Maven.

Jake

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Maven build for compiling JavaScript project

Posted by Manos Batsis <ma...@geekologue.com>.
On 08/25/2010 11:43 PM, Jacob Beard wrote:
> On 10-08-25 02:41 PM, Manos Batsis wrote:
>> The way I get this, you don't have to change the behavior of Maven's
>> compiler plugin.
>>
>> If you check out [1], you'll see there are plenty of lifecycle phases
>> to hook your ant tasks (or whatnot) and perform steps 1, 2 and 3.
>>
>> For example, I'd probably use generate-(re)sources/process-(re)sources
>> to perform 1 and 2.
>>
>> For step 3, generate-sources is greate for code generation (i.e. if
>> that jsc thingy produces .java code), otherwise I'd just throw in the
>> generated class files in the target during prepare-package or,
>> especially if you need tests, process-classes.

> I think you might be right, the way you describe may better integrate
> with the Maven lifecycle than having tasks 1,2 and 3 all be executed
> within the compile phase. However, it's not clear to me how what you
> propose could be implemented using the Maven AntRun plugin. The reason
> for this is that, currently in the Ant script, tasks 1, 2, and 3 depend
> on one-another such that 3 depends on 2, and 2 depends on 1. This is
> desirable, as, when calling the task 3 in the Ant script without Maven,
> tasks 1 and 2 should be executed before 3. If one were to delegate to
> tasks 1, 2, and 3 at different phases in the Maven lifecycle, then
> during the Maven build process, task 1 would be executed, then task 1
> followed by task 2, then task 1 followed by 2 followed by 3. It seems
> like to change this behaviour would involve removing the dependencies in
> the Ant script, which I feel would essentially be "breaking" the script.

You pick any of:

  - Remove the dependencies from the Ant targets and then call each from 
the "appropriate" Maven phase,
  - Introduce new ant targets without the dependencies to call in each 
appropriate Maven phase, thus preserving the old targets and the Ant 
build behavior to be used if needed and when not working with Maven
  - Call 3 from Maven and get done with it.



> If I've misunderstood something, or there's a better way to implement
> this, please let me know.
>>
>> Perhaps you would be interested in helping us implement 1-3 in the
>> maven-jstools-plugin [2] ;-)
> Sure. If you don't mind an Ant dependency, then the work is already done:
>
> https://svn.apache.org/repos/asf/commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml

Thanks I'll take a look.


> If you have a native Maven plugin in mind, that would be something I
> could perhaps assist with in the future as well.

Yes that's what I was thinking, will probably get back to you on that 
after picking at your stuff ;-)

Cheers,

Manos

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Maven build for compiling JavaScript project

Posted by Jacob Beard <jb...@cs.mcgill.ca>.
Hi Manos,

Replies below:

On 10-08-25 02:41 PM, Manos Batsis wrote:
> The way I get this, you don't have to change the behavior of Maven's 
> compiler plugin.
>
> If you check out [1], you'll see there are plenty of lifecycle phases 
> to hook your ant tasks (or whatnot) and perform steps 1, 2 and 3.
>
> For example, I'd probably use generate-(re)sources/process-(re)sources 
> to perform 1 and 2.
>
> For step 3, generate-sources is greate for code generation (i.e. if 
> that jsc thingy produces .java code), otherwise I'd just throw in the 
> generated class files in the target during prepare-package or, 
> especially if you need tests, process-classes.
I think you might be right, the way you describe may better integrate 
with the Maven lifecycle than having tasks 1,2 and 3 all be executed 
within the compile phase. However, it's not clear to me how what you 
propose could be implemented using the Maven AntRun plugin. The reason 
for this is that, currently in the Ant script, tasks 1, 2, and 3 depend 
on one-another such that 3 depends on 2, and 2 depends on 1. This is 
desirable, as, when calling the task 3 in the Ant script without Maven, 
tasks 1 and 2 should be executed before 3. If one were to delegate to 
tasks 1, 2, and 3 at different phases in the Maven lifecycle, then 
during the Maven build process, task 1 would be executed, then task 1 
followed by task 2, then task 1 followed by 2 followed by 3. It seems 
like to change this behaviour would involve removing the dependencies in 
the Ant script, which I feel would essentially be "breaking" the script.

If I've misunderstood something, or there's a better way to implement 
this, please let me know.
>
> Perhaps you would be interested in helping us implement 1-3 in the 
> maven-jstools-plugin [2] ;-)
Sure. If you don't mind an Ant dependency, then the work is already done:

https://svn.apache.org/repos/asf/commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml

If you have a native Maven plugin in mind, that would be something I 
could perhaps assist with in the future as well.

Thanks,

Jake

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Maven build for compiling JavaScript project

Posted by Manos Batsis <ma...@geekologue.com>.
On 08/25/2010 06:05 PM, Jacob Beard wrote:
> I'm working on a Commons sandbox component which is written mostly in
> JavaScript. I currently have an ant build which includes tasks to do the
> following:
>
> 1. combine all of the JavaScript modules into a single file
> 2. minify the combined JavaScript file using the Google Closure
> JavaScript compiler
> 3. compile the combined JavaScript file to a single Java class file
> using the Rhino jsc compiler
> 4. create an executable JAR containing the class file.
>
> I'm interested in working toward releasing the project, and so I'm
> trying to determine what would be the most elegant way to now build this
> project with Maven. Based on my understanding of the tasks performed by
> Maven when staging a release, it seems to me that the compiler task
> would need to be made to delegate to tasks 1-3 of the project's Ant
> script. After the class file has been created with jsc, I believe the
> Maven jar and assembly tasks should work as though the project were a
> regular Java project.
>
> If my understanding so far is correct, I'm wondering what is the best
> way to override or customize the behaviour of Maven's compiler task so
> that it delegates to Ant (probably via the antrun Maven plugin)?


The way I get this, you don't have to change the behavior of Maven's 
compiler plugin.

If you check out [1], you'll see there are plenty of lifecycle phases to 
hook your ant tasks (or whatnot) and perform steps 1, 2 and 3.

For example, I'd probably use generate-(re)sources/process-(re)sources 
to perform 1 and 2.

For step 3, generate-sources is greate for code generation (i.e. if that 
jsc thingy produces .java code), otherwise I'd just throw in the 
generated class files in the target during prepare-package or, 
especially if you need tests, process-classes.

Step 4 will be taken care of by maven automatically using the default 
jar packaging.

Perhaps you would be interested in helping us implement 1-3 in the 
maven-jstools-plugin [2] ;-)

[1] 
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference

[2] http://dev.abiss.gr/mvn-jstools

hth,

Manos


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Maven build for compiling JavaScript project

Posted by Justin Edelson <ju...@gmail.com>.
Assuming that you want to continue to use your build.xml for 1-3, then
you just need to bind the antrun plugin's run goal to the compile phase.

Maven doesn't have tasks. It has goals and phases.

Justin

On 8/25/10 11:05 AM, Jacob Beard wrote:
> Hi,
> 
> I'm working on a Commons sandbox component which is written mostly in
> JavaScript. I currently have an ant build which includes tasks to do the
> following:
> 
> 1. combine all of the JavaScript modules into a single file
> 2. minify the combined JavaScript file using the Google Closure
> JavaScript compiler
> 3. compile the combined JavaScript file to a single Java class file
> using the Rhino jsc compiler
> 4. create an executable JAR containing the class file.
> 
> I'm interested in working toward releasing the project, and so I'm
> trying to determine what would be the most elegant way to now build this
> project with Maven. Based on my understanding of the tasks performed by
> Maven when staging a release, it seems to me that the compiler task
> would need to be made to delegate to tasks 1-3 of the project's Ant
> script. After the class file has been created with jsc, I believe the
> Maven jar and assembly tasks should work as though the project were a
> regular Java project.
> 
> If my understanding so far is correct, I'm wondering what is the best
> way to override or customize the behaviour of Maven's compiler task so
> that it delegates to Ant (probably via the antrun Maven plugin)?
> 
> I'd appreciate any guidance anyone can provide. Thanks,
> 
> Jake
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Maven build for compiling JavaScript project

Posted by Jacob Beard <jb...@cs.mcgill.ca>.
Justin and Olivier,

Thanks for the replies. I now have a better understanding of how Maven 
works, and have been able to get this working.

Jake

On 10-08-25 11:14 AM, Olivier Lamy wrote:
> Hi,
>
> You must have a look at create your own packaging (ie javascript) with
> a custom lifecycle.
> There is a sample for something similar to your use case here :
> http://svn.codehaus.org/mojo/trunk/sandbox/javascript-maven-tools/
>
> 2010/8/25 Jacob Beard<jb...@cs.mcgill.ca>:
>    
>> Hi,
>>
>> I'm working on a Commons sandbox component which is written mostly in
>> JavaScript. I currently have an ant build which includes tasks to do the
>> following:
>>
>> 1. combine all of the JavaScript modules into a single file
>> 2. minify the combined JavaScript file using the Google Closure JavaScript
>> compiler
>> 3. compile the combined JavaScript file to a single Java class file using
>> the Rhino jsc compiler
>> 4. create an executable JAR containing the class file.
>>
>> I'm interested in working toward releasing the project, and so I'm trying to
>> determine what would be the most elegant way to now build this project with
>> Maven. Based on my understanding of the tasks performed by Maven when
>> staging a release, it seems to me that the compiler task would need to be
>> made to delegate to tasks 1-3 of the project's Ant script. After the class
>> file has been created with jsc, I believe the Maven jar and assembly tasks
>> should work as though the project were a regular Java project.
>>
>> If my understanding so far is correct, I'm wondering what is the best way to
>> override or customize the behaviour of Maven's compiler task so that it
>> delegates to Ant (probably via the antrun Maven plugin)?
>>
>> I'd appreciate any guidance anyone can provide. Thanks,
>>
>> Jake
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>>      
>
>
>    

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Maven build for compiling JavaScript project

Posted by Olivier Lamy <ol...@apache.org>.
Hi,

You must have a look at create your own packaging (ie javascript) with
a custom lifecycle.
There is a sample for something similar to your use case here :
http://svn.codehaus.org/mojo/trunk/sandbox/javascript-maven-tools/

2010/8/25 Jacob Beard <jb...@cs.mcgill.ca>:
> Hi,
>
> I'm working on a Commons sandbox component which is written mostly in
> JavaScript. I currently have an ant build which includes tasks to do the
> following:
>
> 1. combine all of the JavaScript modules into a single file
> 2. minify the combined JavaScript file using the Google Closure JavaScript
> compiler
> 3. compile the combined JavaScript file to a single Java class file using
> the Rhino jsc compiler
> 4. create an executable JAR containing the class file.
>
> I'm interested in working toward releasing the project, and so I'm trying to
> determine what would be the most elegant way to now build this project with
> Maven. Based on my understanding of the tasks performed by Maven when
> staging a release, it seems to me that the compiler task would need to be
> made to delegate to tasks 1-3 of the project's Ant script. After the class
> file has been created with jsc, I believe the Maven jar and assembly tasks
> should work as though the project were a regular Java project.
>
> If my understanding so far is correct, I'm wondering what is the best way to
> override or customize the behaviour of Maven's compiler task so that it
> delegates to Ant (probably via the antrun Maven plugin)?
>
> I'd appreciate any guidance anyone can provide. Thanks,
>
> Jake
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>



-- 
Olivier
http://twitter.com/olamy
http://fr.linkedin.com/in/olamy
http://www.viadeo.com/fr/profile/olivier.lamy7

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org