Git Product home page Git Product logo

gazelle_java_example's Introduction

Gazelle extension for java demo

This demo uses the gazelle extension from rules_jvm to generate rules for the maven hello world example generated with the following command.

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

External dependencies.

The following dependency was added to the pom.xml file to demonstrate the use of external dependencies.

    <dependency>
	<groupId>com.fasterxml.jackson.core</groupId>
	<artifactId>jackson-databind</artifactId>
	<version>2.15.3</version>
    </dependency>

This way, we are able to use the jackson library in the App.java file.

import com.fasterxml.jackson.databind.ObjectMapper;

To be able to use this dependency when building with Bazel, we will use rules_jvm_external and add it to the maven_install rule of the WORKSPACE file.

maven_install(
    artifacts = [
        "com.fasterxml.jackson.core:jackson-databind:2.15.3"
    ],
	...
)

The maven_install.json Lockfile

As explained here Bazel can pin the external dependencies to the maven_install.json file. This is also important to let gazelle know about these external dependencies for the BUILD files generateion.

To generate the maven_install.json file, follow the instructions from the above link.

Setup gazelle

Setup gazelle as explained here : https://github.com/bazel-contrib/rules_jvm/tree/main/java/gazelle WORKSPACE file and top level BUILD files.

  • Some more dependencies needed to be added in the WORKSPACE file.
  • Because of the following issue this patch is added to the http_archive command that downloads the rules_jvm dependency in the WORKSPACE file.

Configure project specific settings for gazelle in the top level BUILD file

Importantly: tell gazelle about the maven_install.json lockfile so that it can automatically add the external dependencies.

# gazelle:prefix com.mycompany.app
# gazelle:java_maven_install_file maven_install.json

Run gazelle to generate the BUILD files.

bazel run //:gazelle

This will generate Bazel build file

Which contains the java_library that depends on the external jackson one, as well as a java_binary.

Which contains a java_test_suite target.

gazelle_java_example's People

Contributors

ylecornec avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.