Nexus:Maven

From Chorke Wiki
Revision as of 17:46, 19 January 2021 by Shahed (talk | contribs) (→‎References)
Jump to navigation Jump to search
Recipe Types:
──────────────────────────────────────────
nexus/repository/recipe/types
─┬────────────────────────────────────────
 │
 ├─ group
 ├─ proxy
 └─ host
Repositories:
──────────────────────────────────────────
https://cdn.chorke.org/nexus/repository/
─┬────────────────────────────────────────
 ├─ m2-snapshots/      [host ]
 ├─ m2-releases/       [host ]
 ├─ m2-central/        [proxy]
 └─ m2/                [group]

Blob Store

Admin   : https://cdn.chorke.org/nexus/#admin/repository/blobstores
Path    : /nexus-data/blobs/m2-snapshots
Name    : m2-snapshots
Admin   : https://cdn.chorke.org/nexus/#admin/repository/blobstores
Path    : /nexus-data/blobs/m2-releases
Name    : m2-releases
Admin   : https://cdn.chorke.org/nexus/#admin/repository/blobstores
Path    : /nexus-data/blobs/m2-public
Name    : m2-central
Admin   : https://cdn.chorke.org/nexus/#admin/repository/blobstores
Path    : /nexus-data/blobs/m2-group
Name    : m2-group

Repository

Admin   : https://cdn.chorke.org/nexus/#admin/repository/repositories
Version : Snapshot
Layout  : Strict
Deploy  : Allow redeploy
Storage : m2-snapshots
Name    : m2-snapshots
Admin   : https://cdn.chorke.org/nexus/#admin/repository/repositories
Version : Release
Layout  : Strict
Deploy  : Disable redeploy
Storage : m2-releases
Name    : m2-releases
Admin   : https://cdn.chorke.org/nexus/#admin/repository/repositories
Version : Release
Layout  : Permissive
proxy   : https://repo1.maven.org/maven2/
Storage : m2-central
Name    : m2-central
Admin   : https://cdn.chorke.org/nexus/#admin/repository/repositories
Members : m2-snapshots, m2-releases, m2-central
Storage : m2-group
Name    : m2

Security

vim $HOME/.m2/settings.xml

NEXUS_M2_AUTH="Basic `echo -n 'academia:sadaqah!'|openssl base64`";\
cat <<EOF >> $HOME/.m2/settings-academia.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings 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/settings-1.0.0.xsd">
  <!-- <localRepository>\${user.home}/.m2/repository</localRepository> -->
  <servers>
    <server>
      <id>academia</id>
      <configuration>
        <httpHeaders>
          <property>
            <name>Authorization</name>
            <value>$NEXUS_M2_AUTH</value>
          </property>
        </httpHeaders>
      </configuration>
    </server>

    <server>
      <id>academia.snapshots</id>
      <username>username</username>
      <password>password</password>
    </server>
    <server>
      <id>academia.releases</id>
      <username>username</username>
      <password>password</password>
    </server>
  </servers>

  <mirrors>
    <mirror>
      <id>academia</id>
      <name>academia</name>
      <url>https://cdn.chorke.org/nexus/repository/m2/</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>academia</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  
  <activeProfiles>
    <activeProfile>academia</activeProfile>
  </activeProfiles>
</settings>
EOF

vim ./pom.xml

<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <!-- skipped -->

  <distributionManagement>
    <snapshotRepository>
      <id>academia.snapshots</id>
      <url>https://cdn.chorke.org/nexus/repository/m2-snapshots/</url>
    </snapshotRepository>
    <repository>
      <id>academia.releases</id>
      <url>https://cdn.chorke.org/nexus/repository/m2-releases/</url>
    </repository>
  </distributionManagement>
  <!-- skipped -->

  <repositories>
    <repository>
      <id>academia</id>
      <url>https://cdn.chorke.org/nexus/repository/m2/</url>
      <snapshots><enabled>true</enabled></snapshots>
      <releases><enabled>true</enabled></releases>
    </repository>
  </repositories>
  <!-- skipped -->
</project>

mvn clean install
mvn clean deploy -Djava.net.preferIPv4Stack=true

Redirections

for older version only
${NEXUS_INSTALL_DIR}/conf/nexus.properties
nexus.remoteStorage.enableCircularRedirectsForHosts=maven.oracle.com
nexus.remoteStorage.useCookiesForHosts=maven.oracle.com

References