S
S
silentproger2017-01-24 17:01:39
Java
silentproger, 2017-01-24 17:01:39

How to add dependencies from a git repository in Java?

Hello! I'm new to java and can't google how to download the dependency from github. Java has maven, sbt, gradle, and so on, but I didn’t see an example in them where you can simply specify a link to a git turnip and download it. In PHP, the composer simply specified the project name, version, and a link to the repository, and you're done. How about in java?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vorh, 2017-01-24
@silentproger

1) Create a Maven project
2) Open the pom.xml
file By default, the content of the file is something like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>ru.test</groupId>
  <artifactId>test.a</artifactId>
  <packaging>war</packaging>
  <version>1</version>
  <name>name-project</name>

</project>

3) Add a repository
<repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
</repository>

4) Add dependency
<dependency>
    <groupId>com.github.User</groupId>
    <artifactId>Repo name</artifactId>
    <version>Release tag</version>
</dependency>

As a result, the full content of the pom-nickname:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>ru.test</groupId>
    <artifactId>test.a</artifactId>
    <packaging>war</packaging>
    <version>1</version>
    <name>name-project</name>

    <repositories>
           <repository>
               <id>jitpack.io</id>
               <url>https://jitpack.io</url>
           </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.github.User</groupId>
            <artifactId>Repo name</artifactId>
            <version>Release tag</version>
        </dependency>
    </dependencies>
</project>

E
Evgeny Shklyaev, 2017-01-26
@lolchtoo

Everything is much easier on gradle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question