How to configure UglifyJS with Gradle?

2019-08-05 20:36发布


Are there any ready-to-use Gradle plugins to use for UglifyJs? We are trying to configure Uglify something similar to what has been done here, but the owner of that project seems to have his own private artifactory to which he points to, thereby getting access to UglifyAntTask, which is a github-hosted project not following Gradle/Maven etc. (basically non-managed) JAR. We tried downloading this JAR to our project and tried configuring using the options suggested in gradle page as follows:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar') (or)
    compile files('uglifyjs-java-v1.0.jar')
}

Note: The (or) is not there in actual code, I mentioned only to indicate that we tried both options but it was not picking the JAR.

So at a later step, when we gave

ant.taskdef(name: "uglify", classname: "uglify.ant.UglifyTask", classpath: configurations.uglifyjs.asPath)

Gradle throws the following errror:

taskdef class uglify.ant.UglifyTask cannot be found using the classloader AntClassLoader[]

I am hoping that at least some one must have had the need to include non-managed 3rd party JAR and have figured out how to do this, if so, please point the solution/mistake we have made.

Thanks,
Paddy

1条回答
疯言疯语
2楼-- · 2019-08-05 21:17

Here is how the offical Gradle documentation describe it:

configurations {
  uglifyjs
}
dependencies {
  uglifyjs files('uglifyjs-java-v1.0.jar')
}
task uglifyjs << {
  ant.taskdef(name: 'uglifyjs', classname: 'uglify.ant.UglifyTask', classpath: configurations.uglifyjs.asPath)
  ant.uglifyjs( ... UglifyJS Ant Task parameters ... )
}

See http://www.gradle.org/docs/current/userguide/ant.html#N11416

HTH

查看更多
登录 后发表回答