Monday, November 30, 2015

File exists. error: failed to run pack-refs

If you encounter the following error:

Error pulling origin
fatal: Unable to create 'C:/Users/nbp/IdeaProjects/xxx/.git/packed-refs.lock': File exists. error: failed to run pack-refs

do as follows:

del .git/packed-refs.lock

although I don't know why this happened.

Monday, November 23, 2015

How to exclude `src/main/resources` from a jar file in Gradle

To exclude `src/main/resources` from a jar file in Gradle, add the following to `build.gradle`:

processResources {
    exclude '**'
}

How to refresh a snapshot dependency in Gradle

To refresh a snapshot dependency in Gradle, add the following to `build.gradle`:

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

Reference:
https://discuss.gradle.org/t/how-to-get-gradle-to-download-newer-snapshots-to-gradle-cache-when-using-an-ivy-repository/7344

Tuesday, November 17, 2015

ElasticsearchIllegalArgumentException[failed to execute script]; nested: ScriptException[scripts of type [inline], operation [update] and lang [groovy] are disabled];

When you use inline scripting as follows:

$ curl -XPOST 'localhost:9200/customer/external/1/_update?pretty' -d '
{
  "script" : "ctx._source.age += 5"
}'

you might get the following error:

{
  "error" : "ElasticsearchIllegalArgumentException[failed to execute script]; nested: ScriptException[scripts of type [inline], operation [update] and lang [groovy] are disabled]; ",
  "status" : 400
}

Because inlining scripting is disabled since 1.4.3, you should enable inline scripting explicitly as follows:

config/elasticsearch.yml

script.inline: on

You can check the result as follows:

$ curl 'localhost:9200/customer/external/1?pretty'

References:
https://www.elastic.co/guide/en/elasticsearch/reference/1.7/_updating_documents.html
https://www.elastic.co/guide/en/elasticsearch/reference/1.7/modules-scripting.html

Wednesday, November 4, 2015

How to use a constructor when deserializing in Jackson

To use a constructor when deserializing in Jackson,

do as follows:

@Data
public class ClickUrl {

  private final String url;
  private String finalUrl;

  @JsonCreator
  public AdcrClickUrl(@JsonProperty("url") String url) {
    this.url = url;
  }

}

Reference:
http://www.cowtowncoder.com/blog/archives/2011/07/entry_457.html