diff --git a/0004-fix_build_issue_on_riscv.patch b/0004-fix_build_issue_on_riscv.patch
new file mode 100644
index 0000000000000000000000000000000000000000..a41b7fd01f416566622d720660689c56910e4b5a
--- /dev/null
+++ b/0004-fix_build_issue_on_riscv.patch
@@ -0,0 +1,20 @@
+--- hadoop-3.1.4-src/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/main/native/src/lib/primitives.h.ori 2020-07-21 01:17:58.000000000 +0800
++++ hadoop-3.1.4-src/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/main/native/src/lib/primitives.h 2022-09-03 12:43:35.309454600 +0800
+@@ -99,6 +99,8 @@
+ inline uint32_t bswap(uint32_t val) {
+ #ifdef __aarch64__
+ __asm__("rev %w[dst], %w[src]" : [dst]"=r"(val) : [src]"r"(val));
++#elif defined(__ppc64__)||(__PPC64__)||(__powerpc64__)||(__riscv)
++ return __builtin_bswap32(val);
+ #else
+ __asm__("bswap %0" : "=r" (val) : "0" (val));
+ #endif
+@@ -108,6 +110,8 @@
+ inline uint64_t bswap64(uint64_t val) {
+ #ifdef __aarch64__
+ __asm__("rev %[dst], %[src]" : [dst]"=r"(val) : [src]"r"(val));
++#elif defined(__ppc64__)||(__PPC64__)||(__powerpc64__)||(__riscv)
++ return __builtin_bswap64(val);
+ #else
+ #ifdef __X64
+ __asm__("bswapq %0" : "=r" (val) : "0" (val));
diff --git a/0005-upgrade_os-maven_plugin_to_1.7.1.patch b/0005-upgrade_os-maven_plugin_to_1.7.1.patch
new file mode 100644
index 0000000000000000000000000000000000000000..c454971b440a04bfede0eb85ca59d484ab3c5bc2
--- /dev/null
+++ b/0005-upgrade_os-maven_plugin_to_1.7.1.patch
@@ -0,0 +1,11 @@
+--- hadoop-3.1.4-src/hadoop-project/pom.xml.ori 2020-07-21 14:34:40.000000000 +0800
++++ hadoop-3.1.4-src/hadoop-project/pom.xml 2022-08-26 13:33:06.382209900 +0800
+@@ -85,7 +85,7 @@
+
+
+ 0.5.1
+- 1.5.0.Final
++ 1.7.1
+
+ 3.4.13
+ 2.13.0
diff --git a/hadoop-3.1.spec b/hadoop-3.1.spec
index f07e50f6f80a88f03594579181543cb4ee9d210a..3a16db87c49e12c9749277dc4708edf3ee3b9d2c 100644
--- a/hadoop-3.1.spec
+++ b/hadoop-3.1.spec
@@ -12,7 +12,7 @@
%define _binaries_in_noarch_packages_terminate_build 0
Name: hadoop-3.1
Version: 3.1.4
-Release: 7
+Release: 8
Summary: A software platform for processing vast amounts of data
# The BSD license file is missing
# https://issues.apache.org/jira/browse/HADOOP-9849
@@ -36,6 +36,8 @@ Source13: %{real_name}-yarn-site.xml
Patch1: 0001-sys_errlist-undeclared.patch
Patch2: 0002-bugfix-invalid-variable-name.patch
Patch3: 0003-compatible-with-gcc12.patch
+Patch4: 0004-fix_build_issue_on_riscv.patch
+Patch5: 0005-upgrade_os-maven_plugin_to_1.7.1.patch
BuildRoot: %{_tmppath}/%{real_name}-%{version}-%{release}-root
@@ -244,6 +246,9 @@ This package contains files needed to run Apache Hadoop YARN in secure mode.
%prep
%autosetup -p1 -n %{real_name}-%{version}-src
mvn install:install-file -DgroupId=com.google.protobuf -DartifactId=protoc -Dversion=2.5.0 -Dclassifier=linux-aarch_64 -Dpackaging=exe -Dfile=/usr/bin/protoc
+%ifarch riscv64
+mvn install:install-file -DgroupId=com.google.protobuf -DartifactId=protoc -Dversion=2.5.0 -Dclassifier=linux-riscv64 -Dpackaging=exe -Dfile=/usr/bin/protoc
+%endif
mvn install:install-file -DgroupId=org.fusesource.leveldbjni -DartifactId=leveldbjni-all -Dversion=1.8 -Dpackaging=jar -Dfile=/usr/lib/java/leveldbjni-all.jar
mvn install:install-file -DgroupId=org.fusesource.leveldbjni -DartifactId=leveldbjni -Dversion=1.8 -Dpackaging=jar -Dfile=/usr/lib/java/leveldbjni/leveldbjni.jar
mvn install:install-file -DgroupId=org.iq80.leveldb -DartifactId=leveldb-api -Dversion=0.7 -Dpackaging=jar -Dfile=/usr/share/java/leveldb-java/leveldb-api.jar
@@ -305,6 +310,11 @@ then
export CFLAGS="$CFLAGS -mcpu=generic+Crc -Wno-reserved-user-defined-literal"
fi
+%ifarch riscv64
+export MAVEN_OPTS="-Xms2048M -Xmx8000M"
+function keepalive() { while true; do date; sleep 3600; done }
+keepalive &
+%endif
mvn -Dsnappy.lib=/usr/lib64 -Dbundle.snappy -Dcontainer-executor.conf.dir=%{_sysconfdir}/%{real_name} -Pdist,native -DskipTests -DskipIT -Dmaven.javadoc.skip=true package
%install
@@ -1120,6 +1130,10 @@ fi
%config(noreplace) %{_sysconfdir}/%{real_name}/container-executor.cfg
%changelog
+* Sun May 12 2024 Dingli Zhang - 3.1.4-8
+- Fix build on riscv64
+- Upgrade os-maven-plugin to 1.7.1
+
* Wed Oct 11 2023 luofeng - 3.1.4-7
- support clang build