ksoichiro/gradle-web-resource-plugin

Removing whole dependencies directory on :webResourceCompile

sratatata opened this issue · 9 comments

I've configured plugin to copy dependencies to my-website/src/main/webapp/static/lib
however i've also one library which is not downloadable with bower and i keep it in lib directory.
However when I'm starting :webResourceCompile it's removing whole directory.

I would like to have a way to ignore my library.

I know that we are not able to remove only declared dependencies because it could be differ in some cases (when removing dependency from gradle) but in other case it shouldn't remove whole directory.

Any ideas on that?

Maybe I should add some options to handle that.

  1. List option to specify dependencies that should not be removed in lib.dest directory.

    lib {
        excludeFromClean = ["foo", "bar"]
    }
  2. boolean option to specify that lib.dest directory should be removed before copying.

    lib {
        cleanOnUpdate = false
    }

The first one is better in my opinion, but if your dependencies that are not downloadable with bower changes frequently, managing this option might be annoying.

If the second one is false, the plugin won't remove lib.dest directory on each build.
It might be enough for your case, but not cleaning destination directory might cause other problems (unused dependency might be deployed).
Maybe you should clean the directory in other way.

I'll try adding both options later and upload plugin as a SNAPSHOT version.

BTW, what is "not downloadable with bower"?
Is it downloadable with other tools such as npm?

I've added options and uploaded as 1.1.2-SNAPSHOT.
If this modification satisfies your requirement, I'll release it as v1.1.2.
You can try it with following configuration instead of plugins { ... } in your build.gradle.

buildscript {
    repositories {
        maven {
            url uri('https://oss.sonatype.org/content/repositories/snapshots/')
        }
    }
    dependencies {
        classpath 'com.github.ksoichiro:gradle-web-resource-plugin:1.1.2-SNAPSHOT'
    }
}

apply plugin: 'com.github.ksoichiro.web.resource'

God bless yoy. I've just started computer to start working on this PR :) I would check it thanks a lot. I was thinking about this solution.
Not downloadable is for example tinymce which is coming as bower package but language packs for translation are not downloadable (they mentioned some automatic translation downloading, however it's not working and they said it wouldn't - that is what i've been told). That's why we have manually downloaded tinymce from bower and added some language packs inside. Quick and dirty i know. However I can imagine more situations like that can happen. I think this would nice option to be able to exclude directories from cleanup or just disable cleanup.

This works great. What I expected.

However I've noticed some strange behaviour.

My test setup is:

buildscript {
    repositories {
        jcenter()
        maven {
            url uri('https://oss.sonatype.org/content/repositories/snapshots/')
        }
    }
    dependencies {
        classpath 'com.github.ksoichiro:gradle-web-resource-plugin:1.1.2-SNAPSHOT'
    }
}

apply plugin: 'base'
apply plugin: 'com.github.ksoichiro.web.resource'

webResource {
  base {
    src 'src/main'
    dest 'src/main/webapp/static'
  }

  lib {
    excludeFromClean = ["tinymce"]      
  }    

  bower {
    dependencies {
      install name: "bootstrap", version: "latest"
      install name: "angular", version: "latest"
    }
  }
}

I've directory strucutre:

src/main/webapp/static/
├── lib
│   ├── bootstrap
│   └── tinymce
└── lib2
    ├── bootstrap
    └── tinymce

lib is target directory (lib2 is my copy to make tests easier). tinymce is a directory i like to keep.
I'm doing copy:

cp -R src/main/webapp/static/lib2/tinymce/ src/main/webapp/static/lib/tin2

now my structure is like this:

src/main/webapp/static/
└── lib
    ├── bootstrap
    ├── tin2
    └── tinymce

after gradle clean webResourceCompile I would expect to tin2 directory be removed. But it's not always true. (no errors here).

However when I'm run gradle clean webResourceCompile --info it's always true. I've look into your implementation and found nothing.

It's looking like some thread race...

Thanks for checking.
I've confirmed the issue that tin2 is not always removed.
When it's not removed, webResourceCopyBowerDependencies task is skipped as UP-TO-DATE, isn't it?
I think it is Gradle task's behavior:

Note that if a task has an output directory specified, any files added to that directory since the last time it was executed are ignored and will NOT cause the task to be out of date. This is so unrelated tasks may share an output directory without interfering with each other. If this is not the behaviour you want for some reason, consider using TaskOutputs.upToDateWhen()

Maybe I should handle upToDateWhen() to solve this issue.
I'll look into it further.

could be, but it's not so important for now. I found that just interesting. However quotation is seams to be right here.

I'm ready to close this issue.

Thanks for your comment.
OK, as you say it's not so important.
I'll release this change (new options) and close this issue later.

I've released it as v1.1.2.
Closing the issue.