allegro / grunt-maven-plugin

Grunt + Maven integration done right
Other
213 stars 32 forks source link

Support other resource directories - css, less, images etc #25

Closed nalbion closed 10 years ago

nalbion commented 10 years ago

Say I have the following directory structure:

grunt-maven-plugin currently forces me to pick one directory off /webapp/ ("static" by default) - and then I suppose have an extra maven-resources-plugin execution or task in Gruntfile.js copy across the rest of the relevant resources.

I think I will need to add an <extraResources> configuration item:

    /**
     * Extra resource directories (not within &lt;jsSourceDirectory>) that should be
     * copied across to &lt;gruntBuildDirectory>
     */
    @Parameter
    private org.apache.maven.model.Resource[] extraResources;
...
    private Element[] createResourceElements() {
        int size = extraResources == null ? 2 : 2 + extraResources.length;
        List<Element> resourceElements = new ArrayList<Element>(size);

        if( extraResources != null ) {
            for( org.apache.maven.model.Resource resource : extraResources ) {
                Element extraResourceElement = element(name("resource"),
                    element(name("directory"), resource.getDirectory()),
                    element(name("includes"), createExtraResourceIncludeElements(resource)),
                    element(name("filtering"), Boolean.toString(resource.isFiltering()))
                );
                resourceElements.add( extraResourceElement );
            }
        }
...
    /**
     * Create an array of Elements to store the <include>s
     */
    private Element[] createExtraResourceIncludeElements( org.apache.maven.model.Resource resource ) {
        List<String> includes = resource.getIncludes();
        int i = includes.size();
        Element[] includeElements = new Element[i];
        while( i-- != 0 ) {
            String include = includes.get(i);
            includeElements[i] = element(name("include"), include);
        }

        return includeElements;
    }
adamdubiel commented 10 years ago

I'm afraid it would go against motivations of grunt-maven-plugin :) (see "Motivation" paragraph in Readme)

Your current directory structure keeps a lot of stuff directly in webapp/*, making statics (frontend resources) mixed with WAR specific stuff (namely WEB-INF and META-INF). Main idea behind GMP is to keep those things separate. To treat static (fronted) resources as a separate application embedded into Java webapp. That's why GMP wants you to assign single directory as main directory of potentially standalone JS application.

Also having one designated directory for all static content (from Java point of view) makes it easy to create security and caching polices.

So although adding "extra-resources" would be easy, it would be against the philosophy behind GMP.

nalbion commented 10 years ago

...I think https://github.com/allegro/grunt-maven-npm is doing the same thing, but pulling from Grunt rather than pushing from Maven.

This tasks role is to copy raw sources from Maven webapp sources to target-grunt, where Grunt tasks will be executed.

adamdubiel commented 10 years ago

Yes, but it is used in different context (use Maven with "heavy" builds i.e. maven install, use npm tasks when coding frontend stuff, so you see changes immediately).

nalbion commented 10 years ago

That makes sense. static can become an external git repository, imported using git subtree merge - this would probably be more bower-friendly also.

I suppose I can have the grunt tasks rearrange the folders under target-grunt, eg from /static/less' into/css`

adamdubiel commented 10 years ago

That was exactly the point :) Containing all frontend stuff makes it easier to use frontend tools on it without having to worry about Java artifacts.